I have code such as:
public void MethodA()
{
MyManualResetEvent.Reset();
}
public void MethodB()
{
MyManualResetEvent.Set();
}
This works when using MyManualResetEvent.WaitOne() to stop a thread if another thread has called MethodA but not MethodB.
What i want to do now is be able to call MethodA twice, with another thread only continuing if MethodB is called twice, rather than just once.
I’m hoping there’s something in the System.Threading namespace i don’t know about.
Assuming you don’t need to stop a concurrently-executing
BlockedMethodthe instantMethodAis called, this is probably most easily solved with the standard Monitor class.MethodAandMethodBshare a counter which records how many timesMethodAhas been called without a corresponding call toMethodB. TheBlockedMethodmethod only proceeds if that count is 0; if not, it waits forMethodBto signal it that it’s time to proceed.