Class DisposableSemaphore
Represents a semaphore that free other threads when disposing the result of the WaitAsync(CancellationToken) method.
Implements
Inherited Members
Namespace: DevToys.Api
Assembly: DevToys.Api.dll
Syntax
public sealed class DisposableSemaphore : IDisposable
Constructors
DisposableSemaphore(int)
Initializes a new instance of the DisposableSemaphore class.
Declaration
public DisposableSemaphore(int maxTasksCount = 1)
Parameters
Type | Name | Description |
---|---|---|
int | maxTasksCount | The maximum number of concurrent tasks that can be executed. |
Properties
Disposed
Gets a value indicating whether the semaphore has been disposed.
Declaration
public bool Disposed { get; }
Property Value
Type | Description |
---|---|
bool |
IsBusy
Gets a value indicating whether the semaphore is currently busy.
Declaration
public bool IsBusy { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
Dispose()
Releases all resources used by the DisposableSemaphore.
Declaration
public void Dispose()
WaitAsync(CancellationToken)
Asynchronously waits for the semaphore to be available.
Declaration
public Task<IDisposable> WaitAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<IDisposable> | An IDisposable object that should be disposed to release the semaphore. |