Handling events from a worker thread in the main thread 
Author Message
 Handling events from a worker thread in the main thread

What are the typical ways to handle events generated by a worker thread from
within the main thread?  From these discussions it looks like the
pre{*filter*} method is to call Control.BeginInvoke (perhaps using the
application's main form object).  But is this the only way to accomplish
this?  I was thinking that maybe it could also be accomplished by creating a
stream object that is to be written to by the worker process and read
asyncronously from the main thread, but after thinking it through, I believe
that won't work because the async callback method will get called in the
context of another thread created by the runtime.  If it turns out that the
Control.BeginInvoke route is the only workable solution, I can go ahead and
go with it, but I was just trying to investigate if there are any other ways
to do this before I begin implementing this technique.


Wed, 26 Jan 2005 14:35:59 GMT  
 Handling events from a worker thread in the main thread
Hi Cory!

You might try Control.Invoke, which does the same thing, but synchronously.

Control.BeginInvoke, though, is the best way to do this -- like
Control.Invoke, it's thread-safe and will keep deadlock situations from
occurring.

Hope that helps!

Cat Francis and Matthew Stoecker
Visual Basic User Education
Microsoft Corporation

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> What are the typical ways to handle events generated by a worker thread
from
> within the main thread?  From these discussions it looks like the
> pre{*filter*} method is to call Control.BeginInvoke (perhaps using the
> application's main form object).  But is this the only way to accomplish
> this?  I was thinking that maybe it could also be accomplished by creating
a
> stream object that is to be written to by the worker process and read
> asyncronously from the main thread, but after thinking it through, I
believe
> that won't work because the async callback method will get called in the
> context of another thread created by the runtime.  If it turns out that
the
> Control.BeginInvoke route is the only workable solution, I can go ahead
and
> go with it, but I was just trying to investigate if there are any other
ways
> to do this before I begin implementing this technique.



Sat, 29 Jan 2005 03:59:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. worker thread vs main thread?

2. component in main threads used in worker threads

3. How to Send messages from worker thread to main thread

4. Synchronization problem between main thread and worker thread

5. Posting a message from a worker thread to the main app thread

6. Exe server threading model - events from worker thread question

7. main GUI thread -vs- Main Frame Thread

8. Posting messages to the main window from worker threads

9. Worker thread events using attributed ATL

10. COM Threading Model for ISAPI Worker Threads

11. Firing events from a worker thread

12. Firing events from worker threads

 

 
Powered by phpBB® Forum Software