[threadpool] Do not swallow exception in RegisterWaitForSingleObject callback (#4408)
[mono.git] / mcs / class / corlib / System.Threading / RegisteredWaitHandle.cs
index 1c8f4768d318aeb2ebb6f2eee416da7676e5fa15..3bd11264b1a8fd04c929d3e03b624fb743621c0b 100644 (file)
@@ -84,7 +84,7 @@ namespace System.Threading
                                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
@@ -98,17 +98,16 @@ namespace System.Threading
 
                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);
+                               }
                        }
                }