ManualResetEvent choose which thread?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pujo Aji

    ManualResetEvent choose which thread?

    Hello,

    I use ManualResetEven t to stop and allow a thread running by setting:
    public static ManualResetEven t mre = new ManualResetEven t(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....
  • Rob Levine

    #2
    Re: ManualResetEven t choose which thread?

    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


    "Pujo Aji" <ajikoe@yahoo.c om> wrote in message
    news:opskju9agh d3sg8l@ajinote. ..
    Hello,

    I use ManualResetEven t to stop and allow a thread running by setting:
    public static ManualResetEven t mre = new ManualResetEven t(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....


    Comment

    Working...