Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Semaphore.TryOpenExisting Method (String, Semaphore)

.NET Framework 4.5

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

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

[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public static bool TryOpenExisting(
	string name,
	out Semaphore result
)

Parameters

name
Type: System.String

The name of the system semaphore to open.

result
Type: System.Threading.Semaphore

When this method returns, contains a Semaphore object that represents the named semaphore 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 semaphore was opened successfully; otherwise, false.

ExceptionCondition
ArgumentException

name is an empty string.

-or-

name is longer than 260 characters.

ArgumentNullException

name is null.

IOException

A Win32 error occurred.

UnauthorizedAccessException

The named semaphore exists, but the user does not have the security access required to use it.

If the named semaphore does not exist, this method does not create it. To create the system semaphore when it does not already exist, use one of the Semaphore constructors that has a name parameter.

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

This method overload is equivalent to calling the TryOpenExisting method overload and specifying SemaphoreRights.Synchronize and SemaphoreRights.Modify rights, combined by using the bitwise OR operation. Specifying the SemaphoreRights.Synchronize flag allows a thread to enter the semaphore, and specifying the SemaphoreRights.Modify flag allows a thread to call the Release method.

.NET Framework

Supported in: 4.6, 4.5

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft