I'm just curious about the thread and the UI Controls.
According to my test code, when I run the complied .exe file,the thread access the processbar wihout any issue. But when I debug the code, there's an InvalidOperationException. (Whatever the pooled thread or normal thread.)
So I know the thread is not allowed to access the UI Control, but why it's ok when I run the .exe file. Is it an intended design?
PS.I know we can use backgroundworker to make things elegant.
private void button1_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(dothing);//use the pooled thread
//Thread t = new Thread(new ThreadStart(this.ThreadProcSafe));
//t.Start();
}
private void dothing()
{
for (int i = 1; i <= 100; i++)
{
progressBar2.Value = i;
Thread.Sleep(100);
}
}