ManualResetEvent.WaitOne() and ManualResetEvent.Set()

  • Thread starter Thread starter Kovan Akrei
  • Start date Start date
K

Kovan Akrei

Hi,
I would love to know if it is possible some how to ensure that a thread T1
does not call T2.myResetEvent.Set() before T1 has blocked by calling
T1.myResetEvent.WaitOne()? I cant use monitors sense WaitOne() method in
event handlers does not release the lock.

I have the following code in my class:


class MyClass
{
ManaualResetEvent myResetEvent = ManualResetEvent(false);
Thread thread;

// This method changes controll from one thread to another. So in theory
I would like to let the
// thread asossiated with toNext excecute while blocking all other
threads.
private static void ChangeControl(MyClass toNext)
{
MyClass from = currentActive;
currentActive = toNext;
if((toNext.thread.ThreadState & ThreadState.Unstarted) ==
ThreadState.Unstarted)
{
toNext.thread.Start();
}
else
{
//Signal that currentActive is updated.
toNext.myResetEvent.Set();
}

from.myResetEvent.WaitOne();
from.myResetEvent.Reset();
}
}

Many thanks in advance.

Best regards from
Kovan Akrei
 
Sorry Folks,
The text below should be like this:

I would love to know if it is possible some how to ensure that a thread T1
does not call T2.myResetEvent.Set() before T2 has blocked by calling
T2.myResetEvent.WaitOne()? I cant use monitors sense WaitOne() method in
event handlers does not release the lock.


Regards from Kovan
 
Kovan Akrei said:
The text below should be like this:
I would love to know if it is possible some how to ensure that a thread T1
does not call T2.myResetEvent.Set() before T2 has blocked by calling
T2.myResetEvent.WaitOne()? I cant use monitors sense WaitOne() method in
event handlers does not release the lock.
Regards from Kovan

Why is this necessary? I can't see any reason.
 
Back
Top