lock (this) {
_unregistered = true;
if (_callsInProcess == 0 && _finalEvent != null)
- NativeEventCalls.SetEvent_internal (_finalEvent.Handle);
+ NativeEventCalls.SetEvent (_finalEvent.SafeWaitHandle);
}
} catch (ObjectDisposedException) {
// Can happen if we called Unregister before we had time to execute Wait
private void DoCallBack (object timedOut)
{
- if (_callback != null) {
- try {
- _callback (_state, (bool)timedOut);
- } catch {}
- }
-
- lock (this)
- {
- _callsInProcess--;
- if (_unregistered && _callsInProcess == 0 && _finalEvent != null)
- NativeEventCalls.SetEvent_internal (_finalEvent.Handle);
+ try {
+ if (_callback != null)
+ _callback (_state, (bool)timedOut);
+ } finally {
+ lock (this)
+ {
+ _callsInProcess--;
+ if (_unregistered && _callsInProcess == 0 && _finalEvent != null)
+ NativeEventCalls.SetEvent (_finalEvent.SafeWaitHandle);
+ }
}
}