ManualResetEvent choose which thread?

  • Thread starter Thread starter Pujo Aji
  • Start date Start date
P

Pujo Aji

Hello,

I use ManualResetEvent to stop and allow a thread running by setting:
public static ManualResetEvent mre = new ManualResetEvent(false);

So if I use mre.WaitOne(); this let the thread stop
and I can use mre.Set to let the thread do it's process.

The problem is can I use this kind of mechanism to choose which thread
should run, for example I have two threads which in their inside code
there is mre.WaitOne() command.

Then in my code I would like to let the thread 1 only run, by setting
mre.Set().
But the fact is all of my thread are running just after I click mre.Set().

Thanks in advance.
 
Hi Pujo,

A ResetEvent will not let you choose which thread starts running again.
However, you can ensure that only one thread starts (even though you can't
choose which) by using an AutoResetEvent instead.
As soon as a thread returns on the WaitOne() call, the event is
automatically immediately reset so no other threads will run.

Regards,

Rob
http://roblevine.blogspot.com

Hello,

I use ManualResetEvent to stop and allow a thread running by setting:
public static ManualResetEvent mre = new ManualResetEvent(false);

So if I use mre.WaitOne(); this let the thread stop
and I can use mre.Set to let the thread do it's process.

The problem is can I use this kind of mechanism to choose which thread
should run, for example I have two threads which in their inside code
there is mre.WaitOne() command.

Then in my code I would like to let the thread 1 only run, by setting
mre.Set().
But the fact is all of my thread are running just after I click mre.Set().

Thanks in advance.
 
Back
Top