Show / Hide Table of Contents

Class BlockingOperations

Extends Lock and Thread types with cancellation token support for synchronization.

Inheritance
object
BlockingOperations
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext.Threading
Assembly: DotNext.dll
Syntax
public static class BlockingOperations

Methods

View Source

Join(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 token is canceled and the thread is not yet completed; false to return false.

Returns
Type Description
bool

true if the thread stops successfully; false if timeout occurred or token canceled.

Exceptions
Type Condition
ArgumentOutOfRangeException

timeout is invalid.

OperationCanceledException

token interrupts the blocking operation and throwOnCancellation is true.

View Source

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 token is canceled during the lock acquisition; false to return false.

Returns
Type Description
bool

true if the lock is acquired successfully; false if timeout occurred or token canceled.

Exceptions
Type Condition
ArgumentOutOfRangeException

timeout is invalid.

OperationCanceledException

token interrupts lock acquisition and throwOnCancellation is true.

  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾