System 2.0.0.0 4.0.0.0 System.Threading.WaitHandle System.Runtime.InteropServices.ComVisible(false)

Use the class to control access to a pool of resources. Threads enter the semaphore by calling the method, which is inherited from the class, and release the semaphore by calling the method.

The count on a semaphore is decremented each time a thread enters the semaphore, and incremented when a thread releases the semaphore. When the count is zero, subsequent requests block until other threads release the semaphore. When all threads have released the semaphore, the count is at the maximum value specified when the semaphore was created.

There is no guaranteed order, such as FIFO or LIFO, in which blocked threads enter the semaphore.

A thread can enter the semaphore multiple times, by calling the method repeatedly. To release some or all of these entries, the thread can call the parameterless method overload multiple times, or it can call the method overload that specifies the number of entries to be released.

The class does not enforce thread identity on calls to or . It is the programmer's responsibility to ensure that threads do not release the semaphore too many times. For example, suppose a semaphore has a maximum count of two, and that thread A and thread B both enter the semaphore. If a programming error in thread B causes it to call twice, both calls succeed. The count on the semaphore is full, and when thread A eventually calls , a is thrown.

Semaphores are of two types: local semaphores and named system semaphores. If you create a object using a constructor that accepts a name, it is associated with an operating-system semaphore of that name. Named system semaphores are visible throughout the operating system, and can be used to synchronize the activities of processes. You can create multiple objects that represent the same named system semaphore, and you can use the method to open an existing named system semaphore.

A local semaphore exists only within your process. It can be used by any thread in your process that has a reference to the local object. Each object is a separate local semaphore.

Limits the number of threads that can access a resource or pool of resources concurrently.

- Constructor
  2.0.0.0
  4.0.0.0

  This constructor initializes an unnamed semaphore. All threads that use an instance of such a semaphore must have references to the instance.

  If is less than , the effect is the same as if the current thread had called ( minus ) times. If you do not want to reserve any entries for the thread that creates the semaphore, use the same number for and .

  Initializes a new instance of the class, specifying the maximum number of concurrent entries and optionally reserving some entries.

  The initial number of requests for the semaphore that can be granted concurrently.
  The maximum number of requests for the semaphore that can be granted concurrently.
- Constructor
  2.0.0.0
  4.0.0.0

  This constructor initializes a object that represents a named system semaphore. You can create multiple objects that represent the same named system semaphore.

  If the named system semaphore does not exist, it is created with the initial count and maximum count specified by and . If the named system semaphore already exists, and are not used, although invalid values still cause exceptions. If you need to determine whether or not a named system semaphore was created, use the constructor overload instead.

  When you use this constructor overload, the recommended practice is to specify the same number for and . If is less than , and a named system semaphore is created, the effect is the same as if the current thread had called ( minus ) times. However, with this constructor overload there is no way to determine whether a named system semaphore was created.

  If you specify null or an empty string for , a local semaphore is created, as if you had called the constructor overload.

  Because named semaphores are visible throughout the operating system, they can be used to coordinate resource use across process boundaries.

  If you want to find out whether a named system semaphore exists, use the method. The method attempts to open an existing named semaphore, and throws an exception if the system semaphore does not exist.

  Initializes a new instance of the class, specifying the maximum number of concurrent entries, optionally reserving some entries for the calling thread, and optionally specifying the name of a system semaphore object.

  The initial number of requests for the semaphore that can be granted concurrently.
  The maximum number of requests for the semaphore that can be granted concurrently.
  The name of a named system semaphore object.
- Constructor
  2.0.0.0
  4.0.0.0
  To be added.
  To be added.
  To be added.
  To be added.
  To be added.
  To be added.
- Constructor
  2.0.0.0
  4.0.0.0
  System.MonoTODO("CreateSemaphore_internal does not support access control, semaphoreSecurity is ignored")
  To be added.
  To be added.
  To be added.
  To be added.
  To be added.
  To be added.
  To be added.
- Method
  2.0.0.0
  4.0.0.0
  System.Security.AccessControl.SemaphoreSecurity

  The method uses the following combination of flags (combined using the bitwise OR operation) to search for permissions: , , and .

  The user must have rights to call this method, and the semaphore must have been opened with rights.

  On a local semaphore, access control security is irrelevant. If the object does not represent a named system semaphore, this method returns a object that grants all rights to any user.

  Gets the access control security for a named system semaphore.

  A object that represents the access control security for the named system semaphore.

- Method
  2.0.0.0
  4.0.0.0
  System.Threading.Semaphore ``

  The method tries to open the specified named semaphore. If the system semaphore does not exist, this method throws an exception instead of creating the system semaphore. To create the system semaphore when it does not already exist, use one of the constructors that has a parameter.

  Multiple calls to this method that use the same value for do not necessarily return the same object, even though the objects that are returned represent the same named system semaphore.

  This method overload is equivalent to calling the method overload and specifying and rights, combined by using the bitwise OR operation.

  Specifying the flag allows a thread to enter the semaphore, and specifying the flag allows a thread to call the method.

  Opens the specified named semaphore, if it already exists.

  An object that represents the named system semaphore.

  The name of the system semaphore to open.
- Method
  2.0.0.0
  4.0.0.0
  System.Threading.Semaphore `` ``

  The parameter must include the flag to allow threads to enter the semaphore, and the flag to allow threads to call the method.

  The method tries to open an existing named semaphore. If the system semaphore does not exist, this method throws an exception instead of creating the system semaphore. To create the system semaphore when it does not already exist, use one of the constructors that has a parameter.

  Multiple calls to this method that use the same value for do not necessarily return the same object, even though the objects that are returned represent the same named system semaphore.

  Opens the specified named semaphore, if it already exists, with the desired security access.

  An object that represents the named system semaphore.

  The name of the system semaphore to open. A bitwise combination of the enumeration values that represent the desired security access.
- Method
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.PrePrepareMethod
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Int32

  Threads typically use the method to enter the semaphore, and they typically use this method overload to exit.

  If a is thrown by the method, it does not necessarily indicate a problem with the calling thread. A programming error in another thread might have caused that thread to exit the semaphore more times than it entered.

  If the current object represents a named system semaphore, the user must have rights and the semaphore must have been opened with rights.

  Exits the semaphore and returns the previous count.

  The count on the semaphore before the method was called.

- Method
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Int32 ``

  If a thread has entered the semaphore multiple times, this method overload allows the entire semaphore count to be restored with one call.

  If a is thrown by the method, it does not necessarily indicate a problem with the calling thread. A programming error in another thread might have caused that thread to exit the semaphore more times than it entered.

  If the current object represents a named system semaphore, the user must have rights and the semaphore must have been opened with rights.

  Exits the semaphore a specified number of times and returns the previous count.

  The count on the semaphore before the method was called.

  The number of times to exit the semaphore.
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  You can set access control security only on objects that represent named system semaphores.

  The user must have rights to call this method, and the semaphore must have been opened with rights.

  Sets the access control security for a named system semaphore.

  A object that represents the access control security to be applied to the named system semaphore.
- Method
  4.0.0.0
  System.Boolean `` `` To be added. To be added. To be added. To be added. To be added.
- Method
  4.0.0.0
  System.Boolean `` `` `` To be added. To be added. To be added. To be added. To be added. To be added.