public EventWaitHandle(bool initialState, EventResetMode mode, string name) { if (name != null && 260 < name.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", (object)name)); } SafeWaitHandle @event; if (mode != EventResetMode.AutoReset) { if (mode == EventResetMode.ManualReset) { @event = Win32Native.CreateEvent((Win32Native.SECURITY_ATTRIBUTES)null, true, initialState, name); } else { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag", (object)name)); } } else { @event = Win32Native.CreateEvent((Win32Native.SECURITY_ATTRIBUTES)null, false, initialState, name); } if (@event.IsInvalid) { int lastWin32Error = Marshal.GetLastWin32Error(); @event.SetHandleAsInvalid(); if (name != null && name.Length != 0 && 6 == lastWin32Error) { throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", (object)name)); } __Error.WinIOError(lastWin32Error, name); } this.SetHandleInternal(@event); }
public EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew) { bool manual = IsManualReset(mode); Handle = NativeEventCalls.CreateEvent_internal(manual, initialState, name, out createdNew); }
/// <summary>Initializes a new instance of the <see cref="T:System.Threading.EventWaitHandle" /> class, specifying whether the wait handle is initially signaled if created as a result of this call, whether it resets automatically or manually, and the name of a system synchronization event.</summary> /// <param name="initialState">true to set the initial state to signaled if the named event is created as a result of this call; false to set it to nonsignaled.</param> /// <param name="mode">One of the <see cref="T:System.Threading.EventResetMode" /> values that determines whether the event resets automatically or manually.</param> /// <param name="name">The name of a system-wide synchronization event.</param> /// <exception cref="T:System.IO.IOException">A Win32 error occurred.</exception> /// <exception cref="T:System.UnauthorizedAccessException">The named event exists and has access control security, but the user does not have <see cref="F:System.Security.AccessControl.EventWaitHandleRights.FullControl" />.</exception> /// <exception cref="T:System.Threading.WaitHandleCannotBeOpenedException">The named event cannot be created, perhaps because a wait handle of a different type has the same name.</exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="name" /> is longer than 260 characters.</exception> public EventWaitHandle(bool initialState, EventResetMode mode, string name) { bool manual = this.IsManualReset(mode); bool flag; this.Handle = NativeEventCalls.CreateEvent_internal(manual, initialState, name, out flag); }
private static bool IsManualReset (EventResetMode mode) { if ((mode < EventResetMode.AutoReset) || (mode > EventResetMode.ManualReset)) { throw new ArgumentException ("mode"); } return mode == EventResetMode.ManualReset; }
public EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew) { VerifyNameForCreate(name); VerifyMode(mode); CreateEventCore(initialState, mode, name, out createdNew); }
private void CreateEventCore(bool initialState, EventResetMode mode, string name, out bool createdNew) { Debug.Assert(name == null); SafeWaitHandle = WaitSubsystem.NewEvent(initialState, mode); createdNew = true; }
public EventWaitHandle(bool initialState, EventResetMode mode, string name) { if ((name != null) && (260 < name.Length)) { throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", new object[] { name })); } SafeWaitHandle handle = null; switch (mode) { case EventResetMode.AutoReset: handle = Win32Native.CreateEvent(null, false, initialState, name); break; case EventResetMode.ManualReset: handle = Win32Native.CreateEvent(null, true, initialState, name); break; default: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag", new object[] { name })); } if (handle.IsInvalid) { int errorCode = Marshal.GetLastWin32Error(); handle.SetHandleAsInvalid(); if (((name != null) && (name.Length != 0)) && (6 == errorCode)) { throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", new object[] { name })); } __Error.WinIOError(errorCode, name); } base.SetHandleInternal(handle); }
public void EventWaitHandle_Create_BeyondMaxPathLength() { // GetRandomName prevents name collision when two tests run at the same time string name = GetRandomName() + new string('x', Interop.Kernel32.MAX_PATH); EventWaitHandleSecurity security = GetBasicEventWaitHandleSecurity(); EventResetMode mode = EventResetMode.AutoReset; if (PlatformDetection.IsNetFramework) { Assert.Throws <ArgumentException>(() => { CreateEventWaitHandle( initialState: true, mode, name, security, expectedCreatedNew: true).Dispose(); }); } else { using EventWaitHandle created = CreateAndVerifyEventWaitHandle( initialState: true, mode, name, security, expectedCreatedNew: true); using EventWaitHandle openedByName = EventWaitHandle.OpenExisting(name); Assert.NotNull(openedByName); } }
public void EventWaitHandle_Create_InvalidMode(EventResetMode mode) { if (PlatformDetection.IsNetFramework) { Assert.Throws <ArgumentException>(() => { CreateEventWaitHandle( initialState: true, mode, GetRandomName(), GetBasicEventWaitHandleSecurity(), expectedCreatedNew: true).Dispose(); }); } else { Assert.Throws <ArgumentOutOfRangeException>("mode", () => { CreateEventWaitHandle( initialState: true, mode, GetRandomName(), GetBasicEventWaitHandleSecurity(), expectedCreatedNew: true).Dispose(); }); } }
static public EventWaitHandle CreateWaitHandle(string id, bool initState, EventResetMode resetMode, bool allowEveryone) { //EventResetMode.AutoReset: Set()後,不管有無進入WaitOne(),馬上被自動reset EventWaitHandle eventWaitHandle; bool createNew; if (allowEveryone) { //避免跨Process因權限不足產生WinIOError (Access to the path 'id' is denied.) // create a rule that allows anybody in the "Users" group to synchronise with us //var users = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null); EventWaitHandleSecurity evhSec = new EventWaitHandleSecurity(); EventWaitHandleRights rights = EventWaitHandleRights.FullControl;// EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify; EventWaitHandleAccessRule evhAccessRule = new EventWaitHandleAccessRule("Everyone", rights, AccessControlType.Allow); evhSec.AddAccessRule(evhAccessRule); eventWaitHandle = new EventWaitHandle(initState, resetMode, id, out createNew); //eventWaitHandle.SetAccessControl(evhSec); } else { eventWaitHandle = new EventWaitHandle(initState, resetMode, id, out createNew); } return(eventWaitHandle); }
private static void VerifyMode(EventResetMode mode) { if (mode != EventResetMode.AutoReset && mode != EventResetMode.ManualReset) { throw new ArgumentException(SR.Argument_InvalidFlag, nameof(mode)); } }
public void Ctor_NameUsedByOtherSynchronizationPrimitive_Windows(EventResetMode mode) { string name = Guid.NewGuid().ToString("N"); using (Mutex m = new Mutex(false, name)) Assert.Throws <WaitHandleCannotBeOpenedException>(() => new EventWaitHandle(false, mode, name)); }
public EventWaitHandle (bool initialState, EventResetMode mode, string name, out bool createdNew, EventWaitHandleSecurity eventSecurity) { bool manual = IsManualReset (mode); Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out createdNew); }
public EventWaitHandle(bool initialState, EventResetMode mode) { bool created; bool manual = IsManualReset(mode); semaphore = CreateSemaphore(manual, initialState, null, out created); }
public EventWaitHandle(bool initialState, EventResetMode mode, string name) { if(null != name && System.IO.Path.MAX_PATH < name.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong",name)); } Contract.EndContractBlock(); SafeWaitHandle _handle = null; switch(mode) { case EventResetMode.ManualReset: _handle = Win32Native.CreateEvent(null, true, initialState, name); break; case EventResetMode.AutoReset: _handle = Win32Native.CreateEvent(null, false, initialState, name); break; default: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag",name)); }; if (_handle.IsInvalid) { int errorCode = Marshal.GetLastWin32Error(); _handle.SetHandleAsInvalid(); if(null != name && 0 != name.Length && Win32Native.ERROR_INVALID_HANDLE == errorCode) throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle",name)); __Error.WinIOError(errorCode, name); } SetHandleInternal(_handle); }
public EventWaitHandle(bool initialState, EventResetMode mode, string name) { bool created; Handle = NativeEventCalls.CreateEvent_internal((mode == EventResetMode.ManualReset), initialState, name, out created); }
public EventWaitHandle(bool initialState, EventResetMode mode) { bool created; bool manual = IsManualReset(mode); Handle = NativeEventCalls.CreateEvent_internal(manual, initialState, null, out created); }
public EventWaitHandle(bool initialState, EventResetMode mode, string name) { if ((name != null) && (260 < name.Length)) { throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", new object[] { name })); } SafeWaitHandle handle = null; switch (mode) { case EventResetMode.AutoReset: handle = Win32Native.CreateEvent(null, false, initialState, name); break; case EventResetMode.ManualReset: handle = Win32Native.CreateEvent(null, true, initialState, name); break; default: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag", new object[] { name })); } if (handle.IsInvalid) { int errorCode = Marshal.GetLastWin32Error(); handle.SetHandleAsInvalid(); if (((name != null) && (name.Length != 0)) && (6 == errorCode)) { throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", new object[] { name })); } __Error.WinIOError(errorCode, ""); } base.SetHandleInternal(handle); }
private void CreateEventCore(bool initialState, EventResetMode mode, string?name, out bool createdNew) { #if !PLATFORM_WINDOWS if (name != null) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives); } #endif uint eventFlags = initialState ? Interop.Kernel32.CREATE_EVENT_INITIAL_SET : 0; if (mode == EventResetMode.ManualReset) { eventFlags |= (uint)Interop.Kernel32.CREATE_EVENT_MANUAL_RESET; } SafeWaitHandle handle = Interop.Kernel32.CreateEventEx(IntPtr.Zero, name, eventFlags, AccessRights); int errorCode = Marshal.GetLastWin32Error(); if (handle.IsInvalid) { handle.SetHandleAsInvalid(); if (!string.IsNullOrEmpty(name) && errorCode == Interop.Errors.ERROR_INVALID_HANDLE) { throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name)); } throw Win32Marshal.GetExceptionForWin32Error(errorCode, name); } createdNew = errorCode != Interop.Errors.ERROR_ALREADY_EXISTS; SafeWaitHandle = handle; }
public EventWaitHandle(bool initialState, EventResetMode mode) { VerifyMode(mode); bool createdNew; CreateEventCore(initialState, mode, null, out createdNew); }
private bool IsManualReset(EventResetMode mode) { if (mode < EventResetMode.AutoReset || mode > EventResetMode.ManualReset) { throw new ArgumentException("mode"); } return(mode == EventResetMode.ManualReset); }
static bool IsManualReset(EventResetMode mode) { if ((mode < EventResetMode.AutoReset) || (mode > EventResetMode.ManualReset)) { throw new ArgumentException("mode"); } return(mode == EventResetMode.ManualReset); }
private EventWaitHandle CreateEventWaitHandle(bool initialState, EventResetMode mode, string name, EventWaitHandleSecurity expectedSecurity, bool expectedCreatedNew) { EventWaitHandle handle = EventWaitHandleAcl.Create(initialState, mode, name, out bool createdNew, expectedSecurity); Assert.NotNull(handle); Assert.Equal(expectedCreatedNew, createdNew); return(handle); }
public static EventWaitHandle Create( bool initialState, EventResetMode mode, string?name, out bool createdNew, EventWaitHandleSecurity?eventSecurity) { return(new EventWaitHandle(initialState, mode, name, out createdNew, eventSecurity)); }
public EventWaitHandle(bool initialState, EventResetMode mode, string?name, out bool createdNew) { if (mode != EventResetMode.AutoReset && mode != EventResetMode.ManualReset) { throw new ArgumentException(SR.Argument_InvalidFlag, nameof(mode)); } CreateEventCore(initialState, mode, name, out createdNew); }
/// <summary> /// Initializes a new instance of the <see cref="EventWaitHandleLocker"/> class using a /// co-initialized instance of the <see cref="EventWaitHandle"/> class used as the /// wait handle, specifying whether the wait handle is initially signaled if created /// as a result of this call, whether it resets automatically or manually, the name /// of a system synchronization event, and a Boolean variable whose value after the /// call indicates whether the named system event was created. /// </summary> /// <param name="initialState">Specify <c>true</c> to set the initial state to signaled /// if the named event is created as a result of this call; <c>false</c> to set it to /// nonsignaled.</param> /// <param name="mode">One of the <see cref="EventResetMode"/> values /// that determines whether the event resets automatically or manually.</param> /// <param name="name">The name of a system-wide synchronization event.</param> /// <returns></returns> public static EventWaitHandleLocker MakeWithEventHandle(bool initialState, EventResetMode mode, string name) { var eventWaitHandle = new EventWaitHandle(initialState, mode, name); var instance = new EventWaitHandleLocker(eventWaitHandle, mode == EventResetMode.AutoReset); return(instance); }
/// <summary> /// Close any open handles with <paramref name="name"/> and open a new one. /// </summary> /// <param name="name">The handle name.</param> /// <param name="initialState">Initial state.</param> /// <param name="mode">The mode.</param> /// <returns>The new EventWaitHandle created.</returns> public static EventWaitHandle OpenOrCreate(string name, bool initialState, EventResetMode mode) { try { EventWaitHandle.OpenExisting(name).Close(); } catch (WaitHandleCannotBeOpenedException) { } return(new EventWaitHandle(initialState, mode, name)); }
/// <summary> /// Close any open handles with <paramref name="name"/> and open a new one. /// </summary> /// <param name="name">The handle name.</param> /// <param name="initialState">Initial state.</param> /// <param name="mode">The mode.</param> /// <returns>The new EventWaitHandle created.</returns> public static EventWaitHandle OpenOrCreate(string name, bool initialState, EventResetMode mode) { try { EventWaitHandle.OpenExisting(name).Close(); } catch (WaitHandleCannotBeOpenedException) { } return new EventWaitHandle(initialState, mode, name); }
private void CreateEventCore(bool initialState, EventResetMode mode, string?name, out bool createdNew) { if (name != null) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_NamedSynchronizationPrimitives); } SafeWaitHandle = WaitSubsystem.NewEvent(initialState, mode); createdNew = true; }
public EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew) { IntPtr ptr = CreateEvent(IntPtr.Zero, mode == EventResetMode.ManualReset, initialState, name); if (ptr.Equals(IntPtr.Zero)) { throw new ApplicationException("Cannot create " + name); } createdNew = Marshal.GetLastWin32Error() != 0xb7; Handle = ptr; }
[System.Security.SecurityCritical] // auto-generated_required public unsafe EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew, EventWaitHandleSecurity eventSecurity) { if (null != name && System.IO.Path.MAX_PATH < name.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", name)); } Contract.EndContractBlock(); Win32Native.SECURITY_ATTRIBUTES secAttrs = null; #if FEATURE_MACL // For ACL's, get the security descriptor from the EventWaitHandleSecurity. if (eventSecurity != null) { secAttrs = new Win32Native.SECURITY_ATTRIBUTES(); secAttrs.nLength = (int)Marshal.SizeOf(secAttrs); byte[] sd = eventSecurity.GetSecurityDescriptorBinaryForm(); byte * pSecDescriptor = stackalloc byte[sd.Length]; Buffer.Memcpy(pSecDescriptor, 0, sd, 0, sd.Length); secAttrs.pSecurityDescriptor = pSecDescriptor; } #endif SafeWaitHandle _handle = null; Boolean isManualReset; switch (mode) { case EventResetMode.ManualReset: isManualReset = true; break; case EventResetMode.AutoReset: isManualReset = false; break; default: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag", name)); } ; _handle = Win32Native.CreateEvent(secAttrs, isManualReset, initialState, name); int errorCode = Marshal.GetLastWin32Error(); if (_handle.IsInvalid) { _handle.SetHandleAsInvalid(); if (null != name && 0 != name.Length && Win32Native.ERROR_INVALID_HANDLE == errorCode) { throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", name)); } __Error.WinIOError(errorCode, name); } createdNew = errorCode != Win32Native.ERROR_ALREADY_EXISTS; SetHandleInternal(_handle); }
/// <summary> /// Initializes a newly created <see cref="EventWaitHandle"/> object, specifying whether the wait handle is initially signaled, whether it resets automatically or manually, the name of a system synchronization event, and a bool variable whose value after the call indicates whether the named system event was created. /// </summary> /// <param name="initialState">true to set the initial state to signaled, false to set it to nonsignaled.</param> /// <param name="mode">An Threading.EventResetMode value that determines whether the event resets automatically or manually.</param> /// <param name="name">The name of a system-wide synchronization event.</param> /// <param name="createdNew">When this method returns, contains true if the calling thread was granted initial ownership of the named system event; otherwise, false. This parameter is passed uninitialized.</param> public EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew) { IntPtr h = NativeMethods.CreateEvent(IntPtr.Zero, mode == EventResetMode.ManualReset, initialState, name); if (h.Equals(IntPtr.Zero)) { throw new ApplicationException("Cannot create " + name); } createdNew = (Marshal.GetLastWin32Error() == NativeMethods.ERROR_ALREADY_EXISTS); this.Handle = h; }
/// <summary> /// Default Constructor /// </summary> /// <param name="eventName">name of the event to distinguish</param> public EventEx(String eventName = null) : base() { m_eventResetMode=EventResetMode.AutoReset; m_isInitialRaised=true; m_name=eventName; if (m_name == null) m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode); else m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode, m_name); }
public unsafe EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew, EventWaitHandleSecurity eventSecurity) { if (name != null && 260 < name.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", new object[] { name })); } Win32Native.SECURITY_ATTRIBUTES security_ATTRIBUTES = null; if (eventSecurity != null) { security_ATTRIBUTES = new Win32Native.SECURITY_ATTRIBUTES(); security_ATTRIBUTES.nLength = Marshal.SizeOf <Win32Native.SECURITY_ATTRIBUTES>(security_ATTRIBUTES); byte[] securityDescriptorBinaryForm = eventSecurity.GetSecurityDescriptorBinaryForm(); byte * ptr = stackalloc byte[checked (unchecked ((UIntPtr)securityDescriptorBinaryForm.Length) * 1)]; Buffer.Memcpy(ptr, 0, securityDescriptorBinaryForm, 0, securityDescriptorBinaryForm.Length); security_ATTRIBUTES.pSecurityDescriptor = ptr; } bool isManualReset; if (mode != EventResetMode.AutoReset) { if (mode != EventResetMode.ManualReset) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag", new object[] { name })); } isManualReset = true; } else { isManualReset = false; } SafeWaitHandle safeWaitHandle = Win32Native.CreateEvent(security_ATTRIBUTES, isManualReset, initialState, name); int lastWin32Error = Marshal.GetLastWin32Error(); if (safeWaitHandle.IsInvalid) { safeWaitHandle.SetHandleAsInvalid(); if (name != null && name.Length != 0 && 6 == lastWin32Error) { throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", new object[] { name })); } __Error.WinIOError(lastWin32Error, name); } createdNew = (lastWin32Error != 183); base.SetHandleInternal(safeWaitHandle); }
public GlobalNamedEvent(string name, EventResetMode resetMode = EventResetMode.AutoReset) { try { m_globalEvent = EventWaitHandle.OpenExisting(name); } catch (WaitHandleCannotBeOpenedException) { m_globalEvent = new EventWaitHandle(false, resetMode, name); } }
public void EventWaitHandle_Create_SpecificParameters(bool initialState, EventResetMode mode, EventWaitHandleRights rights, AccessControlType accessControl) { EventWaitHandleSecurity security = GetEventWaitHandleSecurity(WellKnownSidType.BuiltinUsersSid, rights, accessControl); CreateAndVerifyEventWaitHandle( initialState, mode, GetRandomName(), security, expectedCreatedNew: true).Dispose(); }
/// <summary> /// Default Constructor /// </summary> /// <param name="eventName">name of the event to distinguish</param> public EventEx() : base() { m_eventResetMode = EventResetMode.AutoReset; m_isInitialRaised=true; if (m_eventResetMode == EventResetMode.AutoReset) m_event = new AutoResetEvent(m_isInitialRaised); else { m_event = new ManualResetEvent(m_isInitialRaised); } }
public EventWaitHandleEx(bool initialState, EventResetMode mode, string name, out bool createdNew) { var handle = NativeMethods.CreateEvent(IntPtr.Zero, mode == EventResetMode.ManualReset, initialState, name); if (handle == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } createdNew = Marshal.GetLastWin32Error() != ERROR_ALREADY_EXISTS; Handle = handle; }
public static bool Create(string name, EventResetMode mode, out EventWaitHandle signal) { var users = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null); var rule = new EventWaitHandleAccessRule(users, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, AccessControlType.Allow); var security = new EventWaitHandleSecurity(); security.AddAccessRule(rule); bool created; signal = new EventWaitHandle(false, mode, @"Global\" + name, out created, security); return created; }
public void Ctor_StateModeNameCreatedNew_Windows(bool initialState, EventResetMode mode) { string name = Guid.NewGuid().ToString("N"); bool createdNew; using (var ewh = new EventWaitHandle(false, EventResetMode.AutoReset, name, out createdNew)) { Assert.True(createdNew); using (new EventWaitHandle(false, EventResetMode.AutoReset, name, out createdNew)) { Assert.False(createdNew); } } }
public unsafe EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew, EventWaitHandleSecurity eventSecurity) { bool flag; if ((name != null) && (260 < name.Length)) { throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", new object[] { name })); } Win32Native.SECURITY_ATTRIBUTES structure = null; if (eventSecurity != null) { structure = new Win32Native.SECURITY_ATTRIBUTES { nLength = Marshal.SizeOf(structure) }; byte[] securityDescriptorBinaryForm = eventSecurity.GetSecurityDescriptorBinaryForm(); byte* pDest = stackalloc byte[1 * securityDescriptorBinaryForm.Length]; Buffer.memcpy(securityDescriptorBinaryForm, 0, pDest, 0, securityDescriptorBinaryForm.Length); structure.pSecurityDescriptor = pDest; } SafeWaitHandle handle = null; switch (mode) { case EventResetMode.AutoReset: flag = false; break; case EventResetMode.ManualReset: flag = true; break; default: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag", new object[] { name })); } handle = Win32Native.CreateEvent(structure, flag, initialState, name); int errorCode = Marshal.GetLastWin32Error(); if (handle.IsInvalid) { handle.SetHandleAsInvalid(); if (((name != null) && (name.Length != 0)) && (6 == errorCode)) { throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", new object[] { name })); } __Error.WinIOError(errorCode, name); } createdNew = errorCode != 0xb7; base.SetHandleInternal(handle); }
public EventWaitHandle(bool initialState, EventResetMode mode, string name) { if (null != name) { if (((int)Interop.Constants.MaxPath) < name.Length) { throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name)); } } Contract.EndContractBlock(); uint eventFlags = initialState ? (uint)Interop.Constants.CreateEventInitialSet : 0; IntPtr unsafeHandle; switch (mode) { case EventResetMode.ManualReset: eventFlags |= (uint)Interop.Constants.CreateEventManualReset; break; case EventResetMode.AutoReset: break; default: throw new ArgumentException(SR.Format(SR.Argument_InvalidFlag, name)); }; unsafeHandle = Interop.mincore.CreateEventEx(IntPtr.Zero, name, eventFlags, (uint)Interop.Constants.EventAllAccess); int errorCode = (int)Interop.mincore.GetLastError(); SafeWaitHandle _handle = new SafeWaitHandle(unsafeHandle, true); if (_handle.IsInvalid) { _handle.SetHandleAsInvalid(); if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode) throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name)); throw ExceptionFromCreationError(errorCode, name); } SafeWaitHandle = _handle; }
public void PingPong(EventResetMode mode) { // Create names for the two events string outboundName = Guid.NewGuid().ToString("N"); string inboundName = Guid.NewGuid().ToString("N"); // Create the two events and the other process with which to synchronize using (var inbound = new EventWaitHandle(true, mode, inboundName)) using (var outbound = new EventWaitHandle(false, mode, outboundName)) using (var remote = RemoteInvoke(PingPong_OtherProcess, mode.ToString(), outboundName, inboundName)) { // Repeatedly wait for one event and then set the other for (int i = 0; i < 10; i++) { Assert.True(inbound.WaitOne(FailWaitTimeoutMilliseconds)); if (mode == EventResetMode.ManualReset) { inbound.Reset(); } outbound.Set(); } } }
public EventWaitHandle(bool initialState, EventResetMode mode, string nameout , System.Boolean& createdNew) {}
public EventWaitHandle(bool initialState, EventResetMode mode, string name) {}
public EventWaitHandle (bool initialState, EventResetMode mode) { bool created; bool manual = IsManualReset (mode); Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, null, out created); }
public void Ctor_NameUsedByOtherSynchronizationPrimitive_Windows(EventResetMode mode) { string name = Guid.NewGuid().ToString("N"); using (Mutex m = new Mutex(false, name)) Assert.Throws<WaitHandleCannotBeOpenedException>(() => new EventWaitHandle(false, mode, name)); }
public XEngineEventWaitHandle(bool initialState, EventResetMode mode) : base(initialState, mode) {}
public void Ctor_StateMode(bool initialState, EventResetMode mode) { using (var ewh = new EventWaitHandle(initialState, mode)) Assert.Equal(initialState, ewh.WaitOne(0)); }
private bool IsManualReset (EventResetMode mode) { if ((mode < EventResetMode.AutoReset) || (mode > EventResetMode.ManualReset)) throw new ArgumentException ("mode"); return (mode == EventResetMode.ManualReset); }
/// <summary> /// Default Constructor /// </summary> /// <param name="isInitialRaised">flag to raise the event on creation</param> /// <param name="eventResetMode">EventResetMode</param> /// <param name="eventName">name of the event to distinguish</param> public EventEx(bool isInitialRaised, EventResetMode eventResetMode, String eventName = null):base() { m_eventResetMode=eventResetMode; m_isInitialRaised=isInitialRaised; m_name=eventName; if(m_name==null) m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode); else m_event=new EventWaitHandle(m_isInitialRaised,m_eventResetMode,m_name); }
public EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew) : this(initialState, mode, name, out createdNew, null) { }
public EventWaitHandle(bool initialState, EventResetMode mode, string nameout , System.Boolean& createdNew, System.Security.AccessControl.EventWaitHandleSecurity eventSecurity) {}
public EventWaitHandle(bool initialState, EventResetMode mode) : this(initialState, mode, null) { }
public EventWaitHandle (bool initialState, EventResetMode mode, string name, out bool createdNew, EventWaitHandleSecurity eventSecurity) { throw new NotSupportedException (); }
public EventWaitHandle (bool initialState, EventResetMode mode, string name) { throw new NotSupportedException (); }
/// <summary> /// Default Copy Constructor /// </summary> /// <param name="b">the object to copy from</param> public EventEx(EventEx b):base(b) { m_isInitialRaised=b.m_isInitialRaised; m_name=b.m_name; m_eventResetMode=b.m_eventResetMode; if (m_name == null) m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode); else m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode, m_name); }
public AsyncWaitHandle(EventResetMode resetMode) { this.resetMode = resetMode; this.syncObject = new object(); }
public unsafe EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew, EventWaitHandleSecurity eventSecurity) { if(null != name && System.IO.Path.MAX_PATH < name.Length) { throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong",name)); } Contract.EndContractBlock(); Win32Native.SECURITY_ATTRIBUTES secAttrs = null; #if FEATURE_MACL // For ACL's, get the security descriptor from the EventWaitHandleSecurity. if (eventSecurity != null) { secAttrs = new Win32Native.SECURITY_ATTRIBUTES(); secAttrs.nLength = (int)Marshal.SizeOf(secAttrs); byte[] sd = eventSecurity.GetSecurityDescriptorBinaryForm(); byte* pSecDescriptor = stackalloc byte[sd.Length]; Buffer.Memcpy(pSecDescriptor, 0, sd, 0, sd.Length); secAttrs.pSecurityDescriptor = pSecDescriptor; } #endif SafeWaitHandle _handle = null; Boolean isManualReset; switch(mode) { case EventResetMode.ManualReset: isManualReset = true; break; case EventResetMode.AutoReset: isManualReset = false; break; default: throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag",name)); }; _handle = Win32Native.CreateEvent(secAttrs, isManualReset, initialState, name); int errorCode = Marshal.GetLastWin32Error(); if (_handle.IsInvalid) { _handle.SetHandleAsInvalid(); if(null != name && 0 != name.Length && Win32Native.ERROR_INVALID_HANDLE == errorCode) throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle",name)); __Error.WinIOError(errorCode, name); } createdNew = errorCode != Win32Native.ERROR_ALREADY_EXISTS; SetHandleInternal(_handle); }