ManualResetEvent choose which thread?

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.
 
R

Rob Levine

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top