D
Dan
I have just discovered the new BackgroundWorker of VS2005 and I'm happily
using its alternative implementations for VS2003 while waiting for the .NET
2.0 release: anyway, I'd like to ask a general question about its usage. Say
I have a worker class whose time-consuming method is wrapped by a
DoWorkEventHandler delegate and added to BackgroundWorker's DoWork. This
method uses the received BackgroundWorker to show its progress percentage
and to abort processing on user request, but in its processing also fires
some events whose args include a copy of an object calculated by this
method. The UI using this worker should update its display to show all the
objects as they are calculated by the worker. To do this, the UI thread
handles the events fired by the worker, but of course these events are on
the worker thread rather than on the UI thread, so I'm back again to the
nasty duty of wrapping some complex UI calls with Invoke to avoid an
exception.
So my question is: is there a better way of handling events fired by a
background worker thread? It would be wonderful if they could somehow got
marshaled to the UI thread as for the progress percentage display with the
BackgroundWorker, without having to modify the worker class or the client...
Thanks to all!
using its alternative implementations for VS2003 while waiting for the .NET
2.0 release: anyway, I'd like to ask a general question about its usage. Say
I have a worker class whose time-consuming method is wrapped by a
DoWorkEventHandler delegate and added to BackgroundWorker's DoWork. This
method uses the received BackgroundWorker to show its progress percentage
and to abort processing on user request, but in its processing also fires
some events whose args include a copy of an object calculated by this
method. The UI using this worker should update its display to show all the
objects as they are calculated by the worker. To do this, the UI thread
handles the events fired by the worker, but of course these events are on
the worker thread rather than on the UI thread, so I'm back again to the
nasty duty of wrapping some complex UI calls with Invoke to avoid an
exception.
So my question is: is there a better way of handling events fired by a
background worker thread? It would be wonderful if they could somehow got
marshaled to the UI thread as for the progress percentage display with the
BackgroundWorker, without having to modify the worker class or the client...
Thanks to all!