3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 /*============================================================
8 ** Class: SafeWaitHandle
11 ** A wrapper for Win32 events (mutexes, auto reset events, and
12 ** manual reset events). Used by WaitHandle.
15 ===========================================================*/
18 using System.Security;
19 using System.Security.Permissions;
20 using System.Runtime.InteropServices;
21 using System.Runtime.CompilerServices;
22 using System.Runtime.ConstrainedExecution;
23 using System.Runtime.Versioning;
24 using Microsoft.Win32;
25 using System.Threading;
27 namespace Microsoft.Win32.SafeHandles {
29 [System.Security.SecurityCritical] // auto-generated_required
30 public sealed class SafeWaitHandle : SafeHandleZeroOrMinusOneIsInvalid
32 // Called by P/Invoke marshaler
33 private SafeWaitHandle() : base(true)
37 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
38 public SafeWaitHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle)
40 SetHandle(existingHandle);
43 [System.Security.SecurityCritical]
44 [ResourceExposure(ResourceScope.Machine)]
45 [ResourceConsumption(ResourceScope.Machine)]
46 override protected bool ReleaseHandle()
49 NativeEventCalls.CloseEvent_internal (handle);
52 return Win32Native.CloseHandle(handle);