Click or drag to resize

InterprocessLockGetNamedSemaphore(Boolean, Int32, Int32) Method

Gets a uniquely named inter-process Semaphore associated with the running application, typically used to detect whether some number of instances of the application are already running.

Namespace: GSF.Threading
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.207-beta+1781b796b2aa7a54013a031eb432fe4ccee31867
Syntax
public static Semaphore GetNamedSemaphore(
	bool perUser = true,
	int maximumCount = 10,
	int initialCount = -1
)
View Source

Parameters

perUser  Boolean  (Optional)
Indicates whether to generate a different name for the Semaphore dependent upon the user running the application.
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 entry assembly; Semaphore is created if it does not exist.
Exceptions
ExceptionCondition
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 assembly's GUID when creating the Semaphore, if it is available. If it is not available, it uses a hash of the simple name of the assembly. Although the name is hashed to help guarantee uniqueness, it is still entirely possible that another application may use that name with the same hashing algorithm to generate its Semaphore name. Therefore, it is best to ensure that the GuidAttribute is defined in the AssemblyInfo of your application.

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\". 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