2
Answers

Using Process Bar

Ask a question

I am trying to start process bar when buton4 is clicked and  stop the process bar when the program is complete(comparisonCompleted = true;) 
I am getting error cross thread operation not valid I tried using background worker but exactly not know how to use it 


private void button4_Click(object sender, EventArgs e)
{
  button4.Enabled = false; 

//---------- 
Thread t = new Thread(GoCompare);
t.IsBackground = true;
t.Start();


private void GoCompare()
{

ProgressBar pBar = new ProgressBar();
Controls.Add(pBar);
pBar.Name = "ProgresBar1";
pBar.Dock = DockStyle.Bottom;
pBar.Style = ProgressBarStyle.Marquee;
pBar.MarqueeAnimationSpeed = 10;
pBar.Width = 100;
pBar.Height = 30;
pBar.Minimum = 0;
pBar.Maximum = 100;
pBar.Value = 100;
 
bool comparisonCompleted;
comparisonCompleted = false;

 /*------------------------------
 ---------------------------------
----------Statements ------------- */



  comparisonCompleted = true;
 pBar.Style = ProgressBarStyle.Continuous;//error
pBar.MarqueeAnimationSpeed = 0;

 }

Answers (2)