Check AutoResetEvent state
-
21-06-2021 - |
Frage
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();
}
Lösung
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.
Andere Tipps
Yes, check the return value
true if the current instance receives a signal; otherwise, false.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow