1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
8 namespace System.Threading
10 public partial class EventWaitHandle : WaitHandle
12 public EventWaitHandle(bool initialState, EventResetMode mode) :
13 this(initialState, mode, null, out _)
17 public EventWaitHandle(bool initialState, EventResetMode mode, string name) :
18 this(initialState, mode, name, out _)
22 public EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew)
24 if (mode != EventResetMode.AutoReset && mode != EventResetMode.ManualReset)
25 throw new ArgumentException(SR.Argument_InvalidFlag, nameof(mode));
27 CreateEventCore(initialState, mode, name, out createdNew);
30 public static EventWaitHandle OpenExisting(string name)
32 EventWaitHandle result;
33 switch (OpenExistingWorker(name, out result))
35 case OpenExistingResult.NameNotFound:
36 throw new WaitHandleCannotBeOpenedException();
37 case OpenExistingResult.NameInvalid:
38 throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));
39 case OpenExistingResult.PathNotFound:
40 throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, name));
46 public static bool TryOpenExisting(string name, out EventWaitHandle result)
48 return OpenExistingWorker(name, out result) == OpenExistingResult.Success;