Click or drag to resize

InterprocessLockGetNamedSemaphore(String, Int32, Int32) Method

Gets a uniquely named inter-process Semaphore associated with the specified name that identifies a source object needing concurrency locking.

Namespace: GSF.Threading
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.218-beta+101eee949414e414795e55a6e73d88938f0177b8
Syntax
public static Semaphore GetNamedSemaphore(
	string name,
	int maximumCount = 10,
	int initialCount = -1
)
View Source

Parameters

name  String
Identifying name of source object needing concurrency locking (e.g., a path and file name).
maximumCount  Int32  (Optional)
The maximum number of requests for the semaphore that can be granted concurrently.
initialCount  Int32  (Optional)
The initial number of requests for the semaphore that can be granted concurrently, or -1 to default to maximumCount.

Return Value

Semaphore
A uniquely named inter-process Semaphore specific to name; Semaphore is created if it does not exist.
Exceptions
ExceptionCondition
ArgumentNullExceptionArgument name cannot be empty, null or white space.
UnauthorizedAccessExceptionThe named semaphore exists, but the user does not have the minimum needed security access rights to use it.
Remarks

This function uses a hash of the name when creating the Semaphore, not the actual name - this way restrictions on the name length do not need to be a user concern. All processes needing an inter-process Semaphore need to use this same function to ensure access to the same Semaphore.

The name can be a string of any length (must not be empty, null or white space) and is not case-sensitive. All hashes of the name used to create the global Semaphore are first converted to lower case.

The Semaphore created is "Global" meaning that it will be accessible to all active application sessions including terminal service sessions. This is accomplished internally by prefixing the Semaphore name with "Global\"; it is not necessary for the user to be concerned with the length or contents of the name in this method as long as the same name is used for each application. Do not use this helper function if you need to create a specifically named or non-global Semaphore, such as when you need to interact with another application using a Semaphore that does not use this function.

See Also