Class BlockingOperations
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.dll
Syntax
public static class BlockingOperations
Methods
View SourceJoin(Thread, TimeSpan, CancellationToken, bool)
Blocks the calling thread until the thread terminates, or the specified time elapses, or the token turns into canceled state.
Declaration
public static bool Join(this Thread thread, TimeSpan timeout, CancellationToken token, bool throwOnCancellation = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Thread | thread | The thread instance. |
| TimeSpan | timeout | The time to wait. |
| CancellationToken | token | The token that can be used to cancel the operation. |
| bool | throwOnCancellation | true to throw OperationCanceledException if |
Returns
| Type | Description |
|---|---|
| bool | true if the thread stops successfully; false if timeout occurred or |
Remarks
The method uses Interrupt() to unblock the calling thread on cancellation.
If the calling thread is interrupted by another party concurrently with cancellation,
that interruption can be consumed by the method. If token is already canceled,
the method makes a single non-blocking attempt.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
| OperationCanceledException |
|
TryEnter(Lock, TimeSpan, CancellationToken, bool)
Tries to acquire an exclusive lock on the specified object with cancellation support.
Declaration
public static bool TryEnter(this Lock @lock, TimeSpan timeout, CancellationToken token, bool throwOnCancellation = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Lock | lock | The object on which to acquire the lock. |
| TimeSpan | timeout | Time to wait for the lock. |
| CancellationToken | token | The token that can be used to cancel the operation. |
| bool | throwOnCancellation | true to throw OperationCanceledException if |
Returns
| Type | Description |
|---|---|
| bool | true if the lock is acquired successfully; false if timeout occurred or |
Remarks
The method uses Interrupt() to unblock the calling thread on cancellation.
If the calling thread is interrupted by another party concurrently with cancellation,
that interruption can be consumed by the method. If token is already canceled,
the method makes a single non-blocking attempt.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
| OperationCanceledException |
|