Update UI from a worker thread on another class

leedo2k

Active member
Joined
Nov 9, 2006
Messages
28
Programming Experience
Beginner
Hi,

This is one great article. Actually the best I have seen yet. I just have one issue if I may raise it here. I am not sure whether it should be on a spearate thread but if this is not the correct place please move it to wherever you see fit.

Well, I have an issue with invoking my main from to update its UI from an external class rather than the same class like you explained. What I am doing is as follows:

1. Declare a public delegate on the form
2. Declare a public procedure on the form
3. Spawn an instance of my external class and do some work and then update public variables in an external module.
4. When done, I get a handle on the main form using
VB.NET:
Application.OpenForms("mainForm")
5. Invoke the UpdateUI procedure in the form like this:
VB.NET:
Application.OpenForms("mainForm").Invoke(New UpdateGUIDelegate(AddressOf mainForm.UpdateUI))

The code proceeds with no errors and by stepping through code I can see the textBoxes get assigned the value in the public variables. however, the form text boxes never show the new values!! I tried using application.doevents but no luck. I also tried adding a check on me.invokeRequired at the begining of the UpdateUI form but it always returned FALSE.

Sample code here: Download 52K
Please help..

Thanks
 
Last edited:
I'm at work so it won't let me download your script. However, you said you stepped through the code and verified that the values are being assigned. Therefore, it leads me to believe it is something graphical in nature.

I would suggest adding a "mainForm.Refresh()" command at the end of the UpdateUI proceedure. That should force the form to be redrawn and show the assigned data.:)
 
No problems..I found out the solutions. By the way, I already tried refreshing the form and it didn't work. The solution was to pass the parent form to the worker thread by introducing a new property to the class called parentForm. Then when instantiating a new object from the class I only need to pass the mainForm instance to it as a property. Then I can invoke the parent from from within the class directly :) Try the code when you are home;)
 
Back
Top