internal SafeWaitHandleFromSafeHandle(SafeHandle handle) { Contract.Requires(!handle.IsInvalid && !handle.IsClosed); SafeWaitHandle waitHandle; bool succeeded = ProcessUtilities.DuplicateHandle( #if FEATURE_SAFE_PROCESS_HANDLE this.GetSafeWaitHandle(), #else new HandleRef(this, ProcessUtilities.GetCurrentProcess()), #endif handle, #if FEATURE_SAFE_PROCESS_HANDLE this.GetSafeWaitHandle(), #else new HandleRef(this, ProcessUtilities.GetCurrentProcess()), #endif out waitHandle, 0, false, ProcessUtilities.DUPLICATE_SAME_ACCESS); if (!succeeded) { throw new NativeWin32Exception(Marshal.GetLastWin32Error(), "Unable to duplicate a process handle for use as a wait handle."); } #if FEATURE_SAFE_PROCESS_HANDLE this.SetSafeWaitHandle(waitHandle); #else SafeWaitHandle = waitHandle; #endif }