diff options
Diffstat (limited to 'src/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.cs')
-rw-r--r-- | src/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.cs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.cs b/src/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.cs new file mode 100644 index 000000000..4cd733b9b --- /dev/null +++ b/src/System.Private.CoreLib/shared/System/Threading/EventWaitHandle.cs @@ -0,0 +1,51 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.IO; + +namespace System.Threading +{ + public partial class EventWaitHandle : WaitHandle + { + public EventWaitHandle(bool initialState, EventResetMode mode) : + this(initialState, mode, null, out _) + { + } + + public EventWaitHandle(bool initialState, EventResetMode mode, string name) : + this(initialState, mode, name, out _) + { + } + + 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); + } + + public static EventWaitHandle OpenExisting(string name) + { + EventWaitHandle result; + switch (OpenExistingWorker(name, out result)) + { + case OpenExistingResult.NameNotFound: + throw new WaitHandleCannotBeOpenedException(); + case OpenExistingResult.NameInvalid: + throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name)); + case OpenExistingResult.PathNotFound: + throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, name)); + default: + return result; + } + } + + public static bool TryOpenExisting(string name, out EventWaitHandle result) + { + return OpenExistingWorker(name, out result) == OpenExistingResult.Success; + } + } +} |