2 using Microsoft.Win32.SafeHandles;
13 [__DynamicallyInvokable]
14 [HostProtection(
SecurityAction.LinkDemand, Synchronization =
true, ExternalThreading =
true)]
21 [SecuritySafeCritical]
22 [__DynamicallyInvokable]
24 : this(initialState, mode, null)
39 [__DynamicallyInvokable]
42 if (name !=
null && 260 < name.Length)
50 safeWaitHandle = Win32Native.CreateEvent(
null, isManualReset:
true, initialState, name);
53 safeWaitHandle = Win32Native.CreateEvent(
null, isManualReset:
false, initialState, name);
58 if (safeWaitHandle.IsInvalid)
61 safeWaitHandle.SetHandleAsInvalid();
62 if (name !=
null && name.Length != 0 && 6 == lastWin32Error)
66 __Error.WinIOError(lastWin32Error, name);
68 SetHandleInternal(safeWaitHandle);
83 [__DynamicallyInvokable]
85 : this(initialState, mode, name, out createdNew, null)
104 if (name !=
null && 260 < name.Length)
108 Win32Native.SECURITY_ATTRIBUTES sECURITY_ATTRIBUTES =
null;
109 if (eventSecurity !=
null)
111 sECURITY_ATTRIBUTES =
new Win32Native.SECURITY_ATTRIBUTES();
112 sECURITY_ATTRIBUTES.nLength =
Marshal.
SizeOf(sECURITY_ATTRIBUTES);
113 byte[] securityDescriptorBinaryForm = eventSecurity.GetSecurityDescriptorBinaryForm();
114 byte* ptr = stackalloc
byte[(int)checked(unchecked((ulong)(uint)securityDescriptorBinaryForm.Length) * 1uL)];
115 Buffer.Memcpy(ptr, 0, securityDescriptorBinaryForm, 0, securityDescriptorBinaryForm.Length);
116 sECURITY_ATTRIBUTES.pSecurityDescriptor = ptr;
123 isManualReset =
true;
126 isManualReset =
false;
131 safeWaitHandle = Win32Native.CreateEvent(sECURITY_ATTRIBUTES, isManualReset, initialState, name);
133 if (safeWaitHandle.IsInvalid)
135 safeWaitHandle.SetHandleAsInvalid();
136 if (name !=
null && name.Length != 0 && 6 == lastWin32Error)
140 __Error.WinIOError(lastWin32Error, name);
142 createdNew = (lastWin32Error != 183);
143 SetHandleInternal(safeWaitHandle);
149 SetHandleInternal(handle);
164 [__DynamicallyInvokable]
186 switch (OpenExistingWorker(name, rights, out result))
188 case OpenExistingResult.NameNotFound:
190 case OpenExistingResult.NameInvalid:
192 case OpenExistingResult.PathNotFound:
193 __Error.WinIOError(3,
"");
213 [__DynamicallyInvokable]
235 return OpenExistingWorker(name, rights, out result) == OpenExistingResult.Success;
245 if (name.Length == 0)
249 if (name !=
null && 260 < name.Length)
251 throw new ArgumentException(Environment.GetResourceString(
"Argument_WaitHandleNameTooLong", name));
254 SafeWaitHandle safeWaitHandle = Win32Native.OpenEvent((
int)rights, inheritHandle:
false, name);
255 if (safeWaitHandle.IsInvalid)
258 if (2 == lastWin32Error || 123 == lastWin32Error)
260 return OpenExistingResult.NameNotFound;
262 if (3 == lastWin32Error)
264 return OpenExistingResult.PathNotFound;
266 if (name !=
null && name.Length != 0 && 6 == lastWin32Error)
268 return OpenExistingResult.NameInvalid;
270 __Error.WinIOError(lastWin32Error,
"");
273 return OpenExistingResult.Success;
280 [SecuritySafeCritical]
281 [__DynamicallyInvokable]
284 bool flag = Win32Native.ResetEvent(safeWaitHandle);
287 __Error.WinIOError();
296 [SecuritySafeCritical]
297 [__DynamicallyInvokable]
300 bool flag = Win32Native.SetEvent(safeWaitHandle);
303 __Error.WinIOError();
313 [SecuritySafeCritical]
326 [SecuritySafeCritical]
329 if (eventSecurity ==
null)
333 eventSecurity.Persist(safeWaitHandle);
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Encapsulates operating system–specific objects that wait for exclusive access to shared resources.
Represents the Windows access control security applied to a named system wait handle....
The exception that is thrown when an attempt is made to open a system mutex, semaphore,...
SafeWaitHandle SafeWaitHandle
Gets or sets the native operating system handle.
bool Set()
Sets the state of the event to signaled, allowing one or more waiting threads to proceed.
static int SizeOf(object structure)
Returns the unmanaged size of an object in bytes.
EventWaitHandle(bool initialState, EventResetMode mode, string name)
Initializes a new instance of the T:System.Threading.EventWaitHandle class, specifying whether the wa...
static bool TryOpenExisting(string name, EventWaitHandleRights rights, out EventWaitHandle result)
Opens the specified named synchronization event, if it already exists, with the desired security acce...
EventWaitHandle(bool initialState, EventResetMode mode)
Initializes a new instance of the T:System.Threading.EventWaitHandle class, specifying whether the wa...
void SetAccessControl(EventWaitHandleSecurity eventSecurity)
Sets the access control security for a named system event.
static bool TryOpenExisting(string name, out EventWaitHandle result)
Opens the specified named synchronization event, if it already exists, and returns a value that indic...
EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew)
Initializes a new instance of the T:System.Threading.EventWaitHandle class, specifying whether the wa...
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
unsafe EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew, EventWaitHandleSecurity eventSecurity)
Initializes a new instance of the T:System.Threading.EventWaitHandle class, specifying whether the wa...
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
EventWaitHandleSecurity GetAccessControl()
Gets an T:System.Security.AccessControl.EventWaitHandleSecurity object that represents the access con...
Represents a thread synchronization event.
The exception that is thrown when one of the arguments provided to a method is not valid.
static EventWaitHandle OpenExisting(string name, EventWaitHandleRights rights)
Opens the specified named synchronization event, if it already exists, with the desired security acce...
Manipulates arrays of primitive types.
EventResetMode
Indicates whether an T:System.Threading.EventWaitHandle is reset automatically or manually after rece...
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
EventWaitHandleRights
Specifies the access control rights that can be applied to named system event objects.
AccessControlSections
Specifies which sections of a security descriptor to save or load.
bool Reset()
Sets the state of the event to nonsignaled, causing threads to block.
static EventWaitHandle OpenExisting(string name)
Opens the specified named synchronization event, if it already exists.