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
semaphore
SemaphoreSlimA semaphore object to enter.
Returns
- SemaphoreEntrySlim
A disposable SemaphoreEntrySlim instance.
Exceptions
- ObjectDisposedException
The
semaphore
has been disposed.
EnterAsync(SemaphoreSlim, CancellationToken)
Enters a SemaphoreSlim instance asynchronously.
public static ValueTask<SemaphoreEntrySlim> EnterAsync(SemaphoreSlim semaphore, CancellationToken cancellationToken = default)
Parameters
semaphore
SemaphoreSlimA semaphore object to enter.
cancellationToken
CancellationTokenOptional CancellationToken to observe.
Returns
- ValueTask<SemaphoreEntrySlim>
A task that returns a disposable SemaphoreEntrySlim instance.
Exceptions
- ObjectDisposedException
The
semaphore
has been disposed.- OperationCanceledException
cancellationToken
was 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
semaphore
SemaphoreSlimA semaphore object to enter.
entered
boolAn out parameter set to true when semaphore has been entered, otherwise false.
Returns
- SemaphoreEntrySlim
A disposable SemaphoreEntrySlim instance. Semaphore will not be entered if
semaphore
has 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
semaphore
SemaphoreSlimA semaphore object to enter.
cancellationToken
CancellationTokenOptional CancellationToken to observe.
Returns
- ValueTask<SemaphoreEntrySlim>
A task that returns a disposable SemaphoreEntrySlim instance. Semaphore will not be entered if
semaphore
has been disposed.
Exceptions
- OperationCanceledException
cancellationToken
was cancelled.