I have been working with C# for about 6 months now, and started working with threads last week. I created an application that has a couple of threads and one of these needs to change the gui. I can't seem to able to do this, so any help on the matter is greatly appreciated.
How many times does this have to be re-answered....
You can ONLY reference controls on the thread that created them. To perform a cross-thread GUI update, you must pass the information back to the UI thread, and let that thread do the work.
The simplest way is with the Invoke method that is supported by every class derived from Control.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009 In theory, there is no difference between theory and paractice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
If Invoke is required, then you properly fire off the cross thread invoke, then fall immediately into the direct access.
You need to fix this or ELSE
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009 In theory, there is no difference between theory and paractice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Just make sure your UI class listens for the events that your delegate(s) fire, and react upon them. If you'd like, I might be able to dig up an example a little later on.
Bookmarks