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