EventWaitHandle.TryOpenExisting EventWaitHandle.TryOpenExisting EventWaitHandle.TryOpenExisting 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) TryOpenExisting(String, EventWaitHandle) TryOpenExisting(String, EventWaitHandle) 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) TryOpenExisting(String, EventWaitHandleRights, EventWaitHandle) TryOpenExisting(String, EventWaitHandleRights, EventWaitHandle) 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) TryOpenExisting(String, EventWaitHandle) TryOpenExisting(String, EventWaitHandle) TryOpenExisting(String, EventWaitHandle)

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

public:
 static bool TryOpenExisting(System::String ^ name, [Runtime::InteropServices::Out] System::Threading::EventWaitHandle ^ % result);
[System.Security.SecurityCritical]
public static bool TryOpenExisting (string name, out System.Threading.EventWaitHandle result);
static member TryOpenExisting : string * EventWaitHandle -> bool
Public Shared Function TryOpenExisting (name As String, ByRef result As EventWaitHandle) As Boolean

Parameters

name
String String String String

The name of the system synchronization event to open.

result
EventWaitHandle EventWaitHandle EventWaitHandle 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.

Exceptions

name is an empty string.

-or-

name is longer than 260 characters.

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

Remarks

If the named synchronization event does not exist, this method does not create it. 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.

Security

SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

TryOpenExisting(String, EventWaitHandleRights, EventWaitHandle) TryOpenExisting(String, EventWaitHandleRights, EventWaitHandle) TryOpenExisting(String, EventWaitHandleRights, EventWaitHandle) 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.

public:
 static bool TryOpenExisting(System::String ^ name, System::Security::AccessControl::EventWaitHandleRights rights, [Runtime::InteropServices::Out] System::Threading::EventWaitHandle ^ % result);
[System.Security.SecurityCritical]
public static bool TryOpenExisting (string name, System.Security.AccessControl.EventWaitHandleRights rights, out System.Threading.EventWaitHandle result);
static member TryOpenExisting : string * System.Security.AccessControl.EventWaitHandleRights * EventWaitHandle -> bool
Public Shared Function TryOpenExisting (name As String, rights As EventWaitHandleRights, ByRef result As EventWaitHandle) As Boolean

Parameters

name
String String String String

The name of the system synchronization event to open.

rights
EventWaitHandleRights EventWaitHandleRights EventWaitHandleRights EventWaitHandleRights

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

result
EventWaitHandle EventWaitHandle EventWaitHandle 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.

Exceptions

name is an empty string.

-or-

name is longer than 260 characters.

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

Remarks

If the named synchronization event does not exist, this method does not create it. 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.

Security

SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Applies to