class SemaphoreSlim

in global :: System . Threading

Represents a lightweight alternative to that limits the number of threads that can access a resource or pool of resources concurrently.


public SemaphoreSlim( int initialCount )

Initializes a new instance of the class, specifying the initial number of requests that can be granted concurrently.

  • initialCount The initial number of requests for the semaphore that can be granted concurrently.

public SemaphoreSlim( int initialCount, int maxCount )

Initializes a new instance of the class, specifying the initial and maximum number of requests that can be granted concurrently.

  • initialCount The initial number of requests for the semaphore that can be granted concurrently.
  • maxCount The maximum number of requests for the semaphore that can be granted concurrently.

public int CurrentCount { get; }

Gets the number of remaining threads that can enter the object.

  • Returns The number of remaining threads that can enter the semaphore.

public int Release( int releaseCount )

Releases the object a specified number of times.

  • releaseCount The number of times to exit the semaphore.
  • Returns The previous count of the .

public bool Wait( int millisecondsTimeout )

Blocks the current thread until it can enter the , using a 32-bit signed integer that specifies the timeout.

  • millisecondsTimeout The number of milliseconds to wait, (-1) to wait indefinitely, or zero to test the state of the wait handle and return immediately.
  • Returns if the current thread successfully entered the ; otherwise, .

public bool Wait( int millisecondsTimeout, CancellationToken cancellationToken )

Blocks the current thread until it can enter the , using a 32-bit signed integer that specifies the timeout, while observing a .

  • millisecondsTimeout The number of milliseconds to wait, (-1) to wait indefinitely, or zero to test the state of the wait handle and return immediately.
  • cancellationToken The to observe.
  • Returns if the current thread successfully entered the ; otherwise, .

public void Wait( CancellationToken cancellationToken )

Blocks the current thread until it can enter the , while observing a .

  • cancellationToken The token to observe.

public bool Wait( TimeSpan timeout )

Blocks the current thread until it can enter the , using a to specify the timeout.

  • timeout A that represents the number of milliseconds to wait, a that represents -1 milliseconds to wait indefinitely, or a that represents 0 milliseconds to test the wait handle and return immediately.
  • Returns if the current thread successfully entered the ; otherwise, .

public bool Wait( TimeSpan timeout, CancellationToken cancellationToken )

Blocks the current thread until it can enter the , using a that specifies the timeout, while observing a .

  • timeout A that represents the number of milliseconds to wait, a that represents -1 milliseconds to wait indefinitely, or a that represents 0 milliseconds to test the wait handle and return immediately.
  • cancellationToken The to observe.
  • Returns if the current thread successfully entered the ; otherwise, .

public Task<bool> WaitAsync( int millisecondsTimeout )

Asynchronously waits to enter the , using a 32-bit signed integer to measure the time interval.

  • millisecondsTimeout The number of milliseconds to wait, (-1) to wait indefinitely, or zero to test the state of the wait handle and return immediately.
  • Returns A task that will complete with a result of if the current thread successfully entered the , otherwise with a result of .

public Task<bool> WaitAsync( int millisecondsTimeout, CancellationToken cancellationToken )

Asynchronously waits to enter the , using a 32-bit signed integer to measure the time interval, while observing a .

  • millisecondsTimeout The number of milliseconds to wait, (-1) to wait indefinitely, or zero to test the state of the wait handle and return immediately.
  • cancellationToken The to observe.
  • Returns A task that will complete with a result of if the current thread successfully entered the , otherwise with a result of .

public Task WaitAsync( CancellationToken cancellationToken )

Asynchronously waits to enter the , while observing a .

  • cancellationToken The token to observe.
  • Returns A task that will complete when the semaphore has been entered.

public Task<bool> WaitAsync( TimeSpan timeout )

Asynchronously waits to enter the , using a to measure the time interval.

  • timeout A that represents the number of milliseconds to wait, a that represents -1 milliseconds to wait indefinitely, or a that represents 0 milliseconds to test the wait handle and return immediately.
  • Returns A task that will complete with a result of if the current thread successfully entered the , otherwise with a result of .

public Task<bool> WaitAsync( TimeSpan timeout, CancellationToken cancellationToken )

Asynchronously waits to enter the , using a to measure the time interval, while observing a .

  • timeout A that represents the number of milliseconds to wait, a that represents -1 milliseconds to wait indefinitely, or a that represents 0 milliseconds to test the wait handle and return immediately.
  • cancellationToken The token to observe.
  • Returns A task that will complete with a result of if the current thread successfully entered the , otherwise with a result of .

public int Release( )

😔 No documentation found.

public Task WaitAsync( )

😔 No documentation found.

public void Dispose( )

😔 No documentation found.

public Type GetType( )

😔 No documentation found.

public string ToString( )

😔 No documentation found.

public bool Equals( object obj )

😔 No documentation found.

public int GetHashCode( )

😔 No documentation found.

public void Wait( )

😔 No documentation found.