Event from other thread

  • Thread starter Thread starter Dirk Reske
  • Start date Start date
D

Dirk Reske

Hello,

I have a class, which starts a new thread.
from this thread events can be fired.
How can i fire this event in the class-creator-thread?


thx
 
Read up on Delegates. You can have the creater pass a Delegate to your
thread and have the thread call the delegate when it wants to notify the
creater.
 
Aidy said:
Read up on Delegates. You can have the creater pass a Delegate to your
thread and have the thread call the delegate when it wants to notify the
creater.

That's only going to help if the creator thread is a UI thread, or
something else which implements ISynchronizeInvoke. Just calling a
delegate created by the creator thread isn't going to make it execute
in that thread.
 
Dirk Reske said:
I have a class, which starts a new thread.
from this thread events can be fired.
How can i fire this event in the class-creator-thread?

Your creator thread will need to be running some kind of message pump,
whether your own or the normal Windows one. If your creator thread is a
UI thread, you can use Control.Invoke/Control.BeginInvoke. Otherwise,
you might want to use a producer/consumer type queue, with the creator
thread waiting on the queue and the other thread putting work items on
the queue.

See http://www.pobox.com/~skeet/csharp/threads/deadlocks.shtml for an
example of a producer/consumer queue.
 
Back
Top