Hello,
I have a thread intensive C# .NET application in which there are two main threads. I have just migrated this application from .NET 1.1 to .NET 2.0 framework. It works perfectly under .NET 1.1
Thread 1 - manages the state of the application.
Thread 2 - creates and updates the controls
In thread 2, the controls are being updated in a thread-safe manner using the Invoke calls since the trigger to update the controls may come from Thread 1. For some reason, the Invoke mechanism doesnt work. I have also tried using the BeginInvoke instead of Invoke, but it doesnt work. Due to this, the application hangs in the Thread 1 because Thread 2 does not update the control and return. It would be great if there is a solution to this issue!
Loading

Danatas GerviRank #4,152 · 361 reputationPosted Aug 4, 2009, 8:28 AM EDT
private delegate void StDelegate(Label Info, string Text); private void SetText(Label Info, string Text) { if (Info.InvokeRequired) { StDelegate DDD = new StDelegate(SetText); Info.Invoke(DDD, new object[] { Info, Text }); } else { if (Text.Length > 2) // not OK { Info.ForeColor = Color.OrangeRed ; } else { Info.ForeColor = Color.LimeGreen ; } Info.Text = Text; } }Danatas GerviRank #4,152 · 361 reputationPosted Aug 4, 2009, 8:31 AM EDT
(from other thread)
Harish Iyer55 reputationPosted Aug 7, 2009, 8:15 PM EDT
I got the answer for my problem. The problem is due to the delayed handle creation for the control. All I had to do was to make sure that the control's handle was created before I used Invoke. The problem is explained well below. I just read it and used it my application and guess what, it worked :).
http://msmvps.com/blogs/nickwienholt/archive/2004/08/18/12023.aspx
All you have to do is force the creation of the handle, as simple as that.