1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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;
}
}
}
|