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();
}

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.


Yes, check the return value

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

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


Need Your Help

how to create methods from arrays or hashes in perl6

perl oop dynamic perl6

I am trying to add new methods to an object dynamicaly.

How to add jvm parameters for a runnable jar?

java eclipse jar jvm-arguments

For the runnable jar that i am creating. it requires xmx1024 as JVM argument. How can i do this ? Or is there any alternative ?