By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,880 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,880 IT Pros & Developers. It's quick & easy.

ManualResetEvent choose which thread?

P: n/a
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.
--
Baby Step, One Step at a time, better and better....
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"Pujo Aji" <aj****@yahoo.com> wrote in message
news:opskju9aghd3sg8l@ajinote...
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.
--
Baby Step, One Step at a time, better and better....
Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.