Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check AutoResetEvent state

Is it possible to check how actually AutoResetEvent object was treated? Is it fired by timeout or by calling Set() from another method?

Here is my code.

private AutoResetEvent autoResetEvent = new AutoResetEvent(false);
private int timeout = 30000;

public void SyncMethod()
{
    // some code before
    autoResetEvent.WaitOne(timeout);
    // if autoResetEvent called by timeout then { do some stuff } 
    // some code after
}
public void AsyncMethod()
{
    // some code before
    // ok I am done
    autoResetEvent.Set();
}
like image 420
Pavel Shchegolevatykh Avatar asked Jul 16 '12 16:07

Pavel Shchegolevatykh


2 Answers

WaitHandle::WaitOne Method (Int32)

Return Value Type: System::Boolean

true if the current instance receives a signal; otherwise, false.

So, false is returned after timeout.

like image 105
Alex F Avatar answered Oct 28 '22 05:10

Alex F


Yes, check the return value

true if the current instance receives a signal; otherwise, false.

http://msdn.microsoft.com/en-us/library/cc189907

like image 32
Eric J. Avatar answered Oct 28 '22 06:10

Eric J.