I'm imitating progressbar value change like:
private void playAnimation()
{
for(int i=1;i<=100;i++)
{
this.progressBar1.Value = i;
System.Threading.Thread.Sleep(20);
percent = i;
}
}
At the same time I try to run another thread, to update label text like "...% completed". Of course I couldn't change text of label that was created in main thread ( I know it's possible using delegates or something like that..), so I created label in the new thread.
private static void percentage()
{
Label threadLabel = new Label();
Point p = new Point(418,290);
threadLabel.Location = p;
threadLabel.Show();
for (int i = 0; i < 100; i++)
threadLabel.Text = i.ToString()+" % completed";
}
static ThreadStart ts = new ThreadStart(percentage);
Thread oThread = new Thread(ts);
.....
oThread.Start();
playAnimation();
oThread.Abort();
However the label doesn't show up, but I can see the text property changes when using debugging or Messageboxes..
Can anybody give me a clue where is the problem? Or at least the correct way to access main form labels from another thread..