Beispiel #1
0
 /// <devdoc>
 ///     Make sure we are watching for a process exit.
 /// </devdoc>
 /// <internalonly/>
 private void EnsureWatchingForExit()
 {
     if (!_watchingForExit)
     {
         lock (this)
         {
             if (!_watchingForExit)
             {
                 Debug.Assert(_haveProcessHandle, "Process.EnsureWatchingForExit called with no process handle");
                 Debug.Assert(Associated, "Process.EnsureWatchingForExit called with no associated process");
                 _watchingForExit = true;
                 try
                 {
                     _waitHandle           = new ProcessWaitHandle(GetWaitState());
                     _registeredWaitHandle = ThreadPool.RegisterWaitForSingleObject(_waitHandle,
                                                                                    new WaitOrTimerCallback(CompletionCallback), _waitHandle, -1, true);
                 }
                 catch
                 {
                     _waitHandle?.Dispose();
                     _waitHandle      = null;
                     _watchingForExit = false;
                     throw;
                 }
             }
         }
     }
 }