- try
- {
- WaitHandle[] waits = new WaitHandle[] {_waitObject, _cancelEvent};
- do
- {
- int signal = WaitHandle.WaitAny (waits, _timeout, false);
- if (!_unregistered)
- {
- lock (this) { _callsInProcess++; }
- ThreadPool.QueueUserWorkItem (new WaitCallback (DoCallBack), (signal == WaitHandle.WaitTimeout));
- }
- }
- while (!_unregistered && !_executeOnlyOnce);
- }
- catch {}
+ bool release = false;
+ try {
+ _waitObject.SafeWaitHandle.DangerousAddRef (ref release);
+ try {
+ WaitHandle[] waits = new WaitHandle[] {_waitObject, _cancelEvent};
+ do {
+ int signal = WaitHandle.WaitAny (waits, _timeout, false);
+ if (!_unregistered) {
+ lock (this) {
+ _callsInProcess++;
+ }
+ ThreadPool.QueueUserWorkItem (new WaitCallback (DoCallBack), (signal == WaitHandle.WaitTimeout));
+ }
+ } while (!_unregistered && !_executeOnlyOnce);
+ } catch {
+ }