Struct SemaphoreEntrySlim
A lightweight, disposable object representing an acquired semaphore entry.
public readonly struct SemaphoreEntrySlim : IDisposable
- Implements
- Inherited Members
- Extension Methods
Properties
Entered
Specifies whether or not a semaphore has been entered.
public bool Entered { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Remarks
Releases previously acquired semaphore entry.
Exceptions
- SemaphoreFullException
Attempt to release a semaphore has thrown an exception of this type. See Release() for more information.
Enter(SemaphoreSlim)
Enters a SemaphoreSlim instance by blocking the current thread.
public static SemaphoreEntrySlim Enter(SemaphoreSlim semaphore)
Parameters
semaphoreSemaphoreSlimA semaphore object to enter.
Returns
- SemaphoreEntrySlim
A disposable SemaphoreEntrySlim instance.
Exceptions
- ObjectDisposedException
The
semaphorehas been disposed.
EnterAsync(SemaphoreSlim, CancellationToken)
Enters a SemaphoreSlim instance asynchronously.
public static ValueTask<SemaphoreEntrySlim> EnterAsync(SemaphoreSlim semaphore, CancellationToken cancellationToken = default)
Parameters
semaphoreSemaphoreSlimA semaphore object to enter.
cancellationTokenCancellationTokenOptional CancellationToken to observe.
Returns
- ValueTask<SemaphoreEntrySlim>
A task that returns a disposable SemaphoreEntrySlim instance.
Exceptions
- ObjectDisposedException
The
semaphorehas been disposed.- OperationCanceledException
cancellationTokenwas cancelled.
TryEnter(SemaphoreSlim, out bool)
Attempts to enter a SemaphoreSlim instance by blocking the current thread.
If the semaphore has been disposed, then it will not be entered.
public static SemaphoreEntrySlim TryEnter(SemaphoreSlim semaphore, out bool entered)
Parameters
semaphoreSemaphoreSlimA semaphore object to enter.
enteredboolAn out parameter set to true when semaphore has been entered, otherwise false.
Returns
- SemaphoreEntrySlim
A disposable SemaphoreEntrySlim instance. Semaphore will not be entered if
semaphorehas been disposed.
TryEnterAsync(SemaphoreSlim, CancellationToken)
Attempts to enter a SemaphoreSlim instance asynchronously.
If the semaphore has been disposed, then it will not be entered.
public static ValueTask<SemaphoreEntrySlim> TryEnterAsync(SemaphoreSlim semaphore, CancellationToken cancellationToken = default)
Parameters
semaphoreSemaphoreSlimA semaphore object to enter.
cancellationTokenCancellationTokenOptional CancellationToken to observe.
Returns
- ValueTask<SemaphoreEntrySlim>
A task that returns a disposable SemaphoreEntrySlim instance. Semaphore will not be entered if
semaphorehas been disposed.
Exceptions
- OperationCanceledException
cancellationTokenwas cancelled.