TryOpenExisting Method (String, EventWaitHandle)
Collapse the table of content
Expand the table of content

EventWaitHandle.TryOpenExisting Method (String, EventWaitHandle)

.NET Framework (current version)
 

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

Namespace:   System.Threading
Assembly:  mscorlib (in mscorlib.dll)

[SecurityCriticalAttribute]
public static bool TryOpenExisting(
	string name,
	out EventWaitHandle result
)

Parameters

name
Type: System.String

The name of the system synchronization event to open.

result
Type: System.Threading.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.

Return Value

Type: System.Boolean

true if the named synchronization event was opened successfully; otherwise, false.

Exception Condition
ArgumentException

nameis an empty string.

-or-

name is longer than 260 characters.

ArgumentNullException

name is null.

IOException

A Win32 error occurred.

UnauthorizedAccessException

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

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.

SecurityCriticalAttribute

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

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 4.5
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft