/mcs/class/referencesource/System/services/monitoring/system/diagnosticts/processwaithandle.cs

https://github.com/pruiz/mono · C# · 38 lines · 31 code · 4 blank · 3 comment · 1 complexity · 0402b7b0945dfe3f921632e0898e1cb9 MD5 · raw file

  1. using System;
  2. using System.Threading;
  3. using Microsoft.Win32;
  4. using Microsoft.Win32.SafeHandles;
  5. using System.Runtime.InteropServices;
  6. using System.Runtime.Versioning;
  7. namespace System.Diagnostics {
  8. internal class ProcessWaitHandle : WaitHandle {
  9. [ResourceExposure(ResourceScope.None)]
  10. [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
  11. internal ProcessWaitHandle( SafeProcessHandle processHandle): base() {
  12. SafeWaitHandle waitHandle = null;
  13. bool succeeded = NativeMethods.DuplicateHandle(
  14. new HandleRef(this, NativeMethods.GetCurrentProcess()),
  15. processHandle,
  16. new HandleRef(this, NativeMethods.GetCurrentProcess()),
  17. out waitHandle,
  18. 0,
  19. false,
  20. NativeMethods.DUPLICATE_SAME_ACCESS);
  21. if (!succeeded) {
  22. #if MONO
  23. // In Mono, Marshal.GetHRForLastWin32Error is not implemented;
  24. // and also DuplicateHandle throws its own exception rather
  25. // than returning false on error, so this code is unreachable.
  26. throw new SystemException("Unknown error in DuplicateHandle");
  27. #else
  28. Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
  29. #endif
  30. }
  31. this.SafeWaitHandle = waitHandle;
  32. }
  33. }
  34. }