Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


EventWaitHandle.TryOpenExisting Method

Definition

Opens a specified named synchronization event, if it already exists, and returns a value that indicates whether the operation succeeded.

Overloads

TryOpenExisting(String, EventWaitHandle)

Opens the specified named synchronization event, if it already exists, and returns a value that indicates whether the operation succeeded.

TryOpenExisting(String, EventWaitHandleRights, EventWaitHandle)

Opens the specified named synchronization event, if it already exists, with the desired security access, and returns a value that indicates whether the operation succeeded.

TryOpenExisting(String, EventWaitHandle)

Source:
EventWaitHandle.cs
Source:
EventWaitHandle.cs
Source:
EventWaitHandle.cs

Opens the specified named synchronization event, if it already exists, and returns a value that indicates whether the operation succeeded.

C#
[System.Security.SecurityCritical]
public static bool TryOpenExisting (string name, out System.Threading.EventWaitHandle result);
C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static bool TryOpenExisting (string name, out System.Threading.EventWaitHandle? result);
C#
public static bool TryOpenExisting (string name, out System.Threading.EventWaitHandle result);
C#
public static bool TryOpenExisting (string name, out System.Threading.EventWaitHandle? result);

Parameters

name
String

The name of the synchronization object to be opened and shared with other processes. The name is case-sensitive. The backslash character (\) is reserved and may only be used to specify a namespace. For more information on namespaces, see the remarks section. There may be further restrictions on the name depending on the operating system. For example, on Unix-based operating systems, the name after excluding the namespace must be a valid file name.

result
EventWaitHandle

When this method returns, contains a EventWaitHandle object that represents the named synchronization event if the call succeeded, or null if the call failed. This parameter is treated as uninitialized.

Returns

true if the named synchronization event was opened successfully; otherwise, false. In some cases, false may be returned for invalid names.

Attributes

Exceptions

name is an empty string.

-or-

.NET Framework only: name is longer than MAX_PATH (260 characters).

name is null.

name is invalid. This can be for various reasons, including some restrictions that may be placed by the operating system, such as an unknown prefix or invalid characters. Note that the name and common prefixes "Global\" and "Local\" are case-sensitive. For some invalid names, the method may return false instead.

-or-

There was some other error. The HResult property may provide more information.

The name is too long. Length restrictions may depend on the operating system or configuration.

The named event exists, but the user does not have the desired security access.

Remarks

The name may be prefixed with Global\ or Local\ to specify a namespace. When the Global namespace is specified, the synchronization object may be shared with any processes on the system. When the Local namespace is specified, which is also the default when no namespace is specified, the synchronization object may be shared with processes in the same session. On Windows, a session is a login session, and services typically run in a different non-interactive session. On Unix-like operating systems, each shell has its own session. Session-local synchronization objects may be appropriate for synchronizing between processes with a parent/child relationship where they all run in the same session. For more information about synchronization object names on Windows, see Object Names.

If a synchronization object of the requested type exists in the namespace, the existing synchronization object is opened. If a synchronization object does not exist in the namespace, or a synchronization object of a different type exists in the namespace, false is returned.

To create the system event when it does not already exist, use one of the EventWaitHandle constructors that has a name parameter.

If you are uncertain whether a named synchronization event exists, use this method overload instead of the OpenExisting(String) method overload, which throws an exception if the synchronization event does not exist.

This method overload is equivalent to calling the TryOpenExisting(String, EventWaitHandleRights, EventWaitHandle) method overload and specifying EventWaitHandleRights.Synchronize and EventWaitHandleRights.Modify rights, combined by using the bitwise OR operation. Specifying the EventWaitHandleRights.Synchronize flag allows a thread to wait on the named system event, and specifying the EventWaitHandleRights.Modify flag allows a thread to call the Set and Reset methods.

Multiple calls to this method that use the same value for name do not necessarily return the same EventWaitHandle object, even though the objects that are returned represent the same named system event.

Applies to

.NET 9 és más verziók
Termék Verziók
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

TryOpenExisting(String, EventWaitHandleRights, EventWaitHandle)

Opens the specified named synchronization event, if it already exists, with the desired security access, and returns a value that indicates whether the operation succeeded.

C#
[System.Security.SecurityCritical]
public static bool TryOpenExisting (string name, System.Security.AccessControl.EventWaitHandleRights rights, out System.Threading.EventWaitHandle result);

Parameters

name
String

The name of the synchronization object to be opened and shared with other processes. The name is case-sensitive. The backslash character (\) is reserved and may only be used to specify a namespace. For more information on namespaces, see the remarks section. There may be further restrictions on the name depending on the operating system. For example, on Unix-based operating systems, the name after excluding the namespace must be a valid file name.

rights
EventWaitHandleRights

A bitwise combination of the enumeration values that represent the desired security access.

result
EventWaitHandle

When this method returns, contains a EventWaitHandle object that represents the named synchronization event if the call succeeded, or null if the call failed. This parameter is treated as uninitialized.

Returns

true if the named synchronization event was opened successfully; otherwise, false. In some cases, false may be returned for invalid names.

Attributes

Exceptions

name is an empty string.

-or-

.NET Framework only: name is longer than MAX_PATH (260 characters).

name is null.

name is invalid. This can be for various reasons, including some restrictions that may be placed by the operating system, such as an unknown prefix or invalid characters. Note that the name and common prefixes "Global\" and "Local\" are case-sensitive. For some invalid names, the method may return false instead.

-or-

There was some other error. The HResult property may provide more information.

The name is too long. Length restrictions may depend on the operating system or configuration.

The named event exists, but the user does not have the desired security access.

Remarks

The name may be prefixed with Global\ or Local\ to specify a namespace. When the Global namespace is specified, the synchronization object may be shared with any processes on the system. When the Local namespace is specified, which is also the default when no namespace is specified, the synchronization object may be shared with processes in the same session. On Windows, a session is a login session, and services typically run in a different non-interactive session. On Unix-like operating systems, each shell has its own session. Session-local synchronization objects may be appropriate for synchronizing between processes with a parent/child relationship where they all run in the same session. For more information about synchronization object names on Windows, see Object Names.

If a synchronization object of the requested type exists in the namespace, the existing synchronization object is opened. If a synchronization object does not exist in the namespace, or a synchronization object of a different type exists in the namespace, false is returned.

To create the system event when it does not already exist, use one of the EventWaitHandle constructors that has a name parameter.

If you are uncertain whether a named synchronization event exists, use this method overload instead of the OpenExisting(String, EventWaitHandleRights) method overload, which throws an exception if the synchronization event does not exist.

The rights parameter must include the EventWaitHandleRights.Synchronize flag to allow threads to wait on the event, and the EventWaitHandleRights.Modify flag to allow threads to call the Set and Reset methods.

Multiple calls to this method that use the same value for name do not necessarily return the same EventWaitHandle object, even though the objects that are returned represent the same named system event.

Applies to

.NET Framework 4.8.1 és más verziók
Termék Verziók
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1