|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Multithreading Invoke WorkaroundWhen multithreading in my Windows form application, every time a non form
thread attempts to raise an event that modifies a control, I get an exception. I understand that to avoid this, one way is to use the control's Invoke method, with a delegate to the sub I would like to invoke. I was wondering if there is any other way to avoid this problem, without having to use an invoke for each event, because with a large number of events, it starts to get confusing and relatively inefficient (if you ask me). I'd just like to know if there's another way to raise events on the main form thread. Thanks! "Joel Merk" <JoelM***@discussions.microsoft.com> schrieb Efficiency at development time or run time? At run time (if you ask me)> When multithreading in my Windows form application, every time a non > form thread attempts to raise an event that modifies a control, I > get an exception. I understand that to avoid this, one way is to use > the control's Invoke method, with a delegate to the sub I would like > to invoke. I was wondering if there is any other way to avoid this > problem, without having to use an invoke for each event, because > with a large number of events, it starts to get confusing and > relatively inefficient (if you ask me). efficiency is not that important because the user is usually the slowest part in the chain. If there's a lot to update, either bulk updates to the UI can be a solution, or don't putting the work in a background thread. > I'd just like to know if The only thing Invoke does is putting a message into the message queue of > there's another way to raise events on the main form thread. Thanks! the UI thread. That's the only way to make it work. Well, the "only" but another one: Using a Timer to poll data from the worker threads. Armin =?Utf-8?B?Sm9lbCBNZXJr?= <JoelM***@discussions.microsoft.com> wrote in
news:7835B1DE-7093-4B72-B6D5-B39C472A550E@microsoft.com: You should use BeginInvoke instead of Invoke... because under certain > When multithreading in my Windows form application, every time a non > form thread attempts to raise an event that modifies a control, I get > an exception. I understand that to avoid this, one way is to use the > control's Invoke method, with a delegate to the sub I would like to > invoke. I was wondering if there is any other way to avoid this > problem, without having to use an invoke for each event, because with > a large number of events, it starts to get confusing and relatively > inefficient (if you ask me). I'd just like to know if there's another > way to raise events on the main form thread. Thanks! situations, Invoke can cause a deadlock. If you're doing a lot of background updates ... perhaps create a helper class or rearchitect your solution so that your code is more centralized? On Nov 26, 1:36 am, Joel Merk <JoelM***@discussions.microsoft.com>
wrote: > When multithreading in my Windows form application, every time a non form Consider having your UI thread poll a data structure for the objects> thread attempts to raise an event that modifies a control, I get an > exception. I understand that to avoid this, one way is to use the control's > Invoke method, with a delegate to the sub I would like to invoke. I was > wondering if there is any other way to avoid this problem, without having to > use an invoke for each event, because with a large number of events, it > starts to get confusing and relatively inefficient (if you ask me). I'd just > like to know if there's another way to raise events on the main form thread. > Thanks! that represent an event.
Removing reference type members from a generic list clone
vs2008 or not Creating a Web Service (Service, not Client) from WSDL XML Deserializer problem Reurning Arrays Editing an indexed PixelFormat Question about Application Layout Convert code line to VB Bug in VWD 2008 Express? working with a com interface |
|||||||||||||||||||||||