Re: best way to receive 'callbacks' in a GUI from other threads
- From: "Brian Gideon" <briangideon@xxxxxxxxx>
- Date: 18 Sep 2006 14:00:45 -0700
Emma,
If the mechanism you're using implies asynchronous behavior then I
would continue doing what you're doing. Most people assume that
callbacks are invoked from the thread running the asynchronous
operation. This is especially the case if you've used the
BeginSomeOperation/EndSomeOperation pattern.
Another option is to pass a reference a form or control to your worker
class and let it do the marshaling for you. Microsoft used a similar
pattern for the System.Timers.Timer object. In that case they created
a SynchronizingObject property that the Timer uses to automatically
marshal the Elapsed event. If SynchronizingObject is null then the
Elapsed event is executed on a ThreadPool thread. I find that to be a
rather elegant pattern especially if the worker class uses events to
report progress.
Brian
emma_middlebrook@xxxxxxxxxxx wrote:
Hi
Advice needed about what's the best in the following situation.
In essence, I have a GUI that needs to detail time taken to do jobs
that execute in their own thread.
Currently, the GUI thread instantiates a class that wraps a job,
handing it a callback (delegate) to call once the job has finished. On
callback, always on a different thread than the GUI thread,
InvokeRequired is tested (and is always true), and the GUI is updated
via Invoke.
Is this standard and best? Or do people out there do something
different? I'm just concerned about the GUI class having to do a
thread-related test. It seems out of place: it shouldn't have to know
that other threads are involved so is there some kind of standard way
to hide this away?
Thanks and any help appreciated!
Emma.
.
- References:
- best way to receive 'callbacks' in a GUI from other threads
- From: emma_middlebrook
- best way to receive 'callbacks' in a GUI from other threads
- Prev by Date: Re: Async sockets and threads
- Next by Date: Re: Wried problem
- Previous by thread: Re: best way to receive 'callbacks' in a GUI from other threads
- Next by thread: Re: Resource for MessageBox
- Index(es):
Relevant Pages
|