I\'m beginner in C#. And i have problem with threads when i using win.forms. My application freezes. What the problem with this code? I\'m using microsoft example from msdn. Her
There is a deadlock - UI thread is waiting for threads to complete with Thread.Join()
while the worker threads are trying to send a message to UI using blocking Control.Invoke()
. Replacing the Invoke in the thread code by BeginInvoke() will make the deadlock go away
if (this.textBox1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(WriteString);
// BeginInvoke posts message to UI thread asyncronously
this.BeginInvoke(d, new object[] { text });
}
else
{
this.textBox1.Text = text.ToString();
}