The Labs \ Source Viewer \ SSCLI \ System.Diagnostics \ ProcessWaitHandle

  1. //------------------------------------------------------------------------------
  2. // <copyright file="ProcessWaitHandle.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. using System;
  16. using System.Threading;
  17. using Microsoft.Win32;
  18. using Microsoft.Win32.SafeHandles;
  19. using System.Runtime.InteropServices;
  20. namespace System.Diagnostics
  21. {
  22.     internal class ProcessWaitHandle : WaitHandle
  23.     {
  24.        
  25.         internal ProcessWaitHandle(SafeProcessHandle processHandle) : base()
  26.         {
  27.             SafeWaitHandle waitHandle = null;
  28.             bool succeeded = NativeMethods.DuplicateHandle(new HandleRef(this, NativeMethods.GetCurrentProcess()), processHandle, new HandleRef(this, NativeMethods.GetCurrentProcess()), out waitHandle, 0, false, NativeMethods.DUPLICATE_SAME_ACCESS);
  29.            
  30.             if (!succeeded) {
  31.                 Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
  32.             }
  33.            
  34.             this.SafeWaitHandle = waitHandle;
  35.         }
  36.     }
  37. }

Developer Fusion