|
-
Aug 19th, 2008, 10:14 AM
#1
Thread Starter
Lively Member
[2005] Update UI from a thread on another class!!!
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
Code:
Application.OpenForms("mainForm")
5. Invoke the UpdateUI procedure in the form like this:
Code:
Application.OpenForms("mainForm").Invoke(New UpdateGUIDelegate(AddressOfmainForm.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 confused:
Last edited by leedo2k; Aug 19th, 2008 at 11:57 AM.
-
Aug 19th, 2008, 12:03 PM
#2
Re: [2005] Update UI from a thread on another class!!!

Try a System.threading.thread.sleep(200) after setting the textbox values and see if they appear.
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Aug 19th, 2008, 12:53 PM
#3
Thread Starter
Lively Member
Re: [2005] Update UI from a thread on another class!!!
Nope, doesn't work.
-
Aug 19th, 2008, 01:10 PM
#4
Re: [2005] Update UI from a thread on another class!!!
Did you do it on the thread that is handling the UI?
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Aug 19th, 2008, 01:25 PM
#5
Re: [2005] Update UI from a thread on another class!!!
I would pass the form instance to the class so that it can update the controls. For instance
Code:
Public Property ParentForm() As MainForm
...
Then you can invoke everything from within your class.
Another option is to pass an ISynchronizeInvoker object to the class and use events in your class. When values are set you invoke the events on the ui thread using the ISynchronizeInvoker Object.
-
Aug 19th, 2008, 01:57 PM
#6
Thread Starter
Lively Member
Re: [2005] Update UI from a thread on another class!!!
 Originally Posted by dolot
Did you do it on the thread that is handling the UI?
Yes, I did. But it did not work. Thanks anyway.
-
Aug 19th, 2008, 01:58 PM
#7
Thread Starter
Lively Member
Re: [2005] Update UI from a thread on another class!!!
 Originally Posted by bmahler
I would pass the form instance to the class so that it can update the controls. For instance
Code:
Public Property ParentForm() As MainForm
...
Then you can invoke everything from within your class.
Yes, that worked. This is abrilliant and at the same time a very clean implementation. Thank very much bmahler
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|