Show / Hide Table of Contents

Class TimeoutSource

Represents reusable timeout tracker that is linked to the root cancellation token.

Inheritance
object
TimeoutSource
Implements
IDisposable
IAsyncDisposable
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public sealed class TimeoutSource : IDisposable, IAsyncDisposable
Remarks

The tracker can be reused multiple times to reduce the memory allocation until it gets timed out or canceled.

Constructors

| Edit this page View Source

TimeoutSource(TimeProvider, CancellationToken)

Initializes a new timeout provider.

Declaration
public TimeoutSource(TimeProvider provider, CancellationToken token)
Parameters
Type Name Description
TimeProvider provider

The time provider.

CancellationToken token

The token that can be used to cancel Token.

Properties

| Edit this page View Source

IsCanceled

Gets a value indicating that this source is canceled by the root token.

Declaration
public bool IsCanceled { get; }
Property Value
Type Description
bool
| Edit this page View Source

IsTimedOut

Gets a value indicating that this source is timed out.

Declaration
public bool IsTimedOut { get; }
Property Value
Type Description
bool
| Edit this page View Source

RootToken

Gets the root token passed to TimeoutSource(TimeProvider, CancellationToken) constructor.

Declaration
public CancellationToken RootToken { get; }
Property Value
Type Description
CancellationToken
| Edit this page View Source

Token

The cancellation token that is linked to the root token and the timeout.

Declaration
public CancellationToken Token { get; }
Property Value
Type Description
CancellationToken

Methods

| Edit this page View Source

Dispose()

Disposes the provider.

Declaration
public void Dispose()
| Edit this page View Source

DisposeAsync()

Disposes the provider asynchronously.

Declaration
public ValueTask DisposeAsync()
Returns
Type Description
ValueTask

The task representing asynchronous state of the operation.

| Edit this page View Source

~TimeoutSource()

Declaration
protected ~TimeoutSource()
| Edit this page View Source

TryReset()

Tries to reset the timer.

Declaration
public bool TryReset()
Returns
Type Description
bool

true if this object can be reused by calling TryStart(TimeSpan) again; otherwise, false.

| Edit this page View Source

TryStart(TimeSpan)

Starts the timer.

Declaration
public bool TryStart(TimeSpan value)
Parameters
Type Name Description
TimeSpan value

The timeout value.

Returns
Type Description
bool

true if the timer is started successfully; otherwise, false.

Remarks

When the timer expires, it turns Token to the canceled state. If this method returns false, Token is in canceled state (or gets canceled soon). However, you can check IsCanceled or IsTimedOut to find out the state of the provider.

Exceptions
Type Condition
ObjectDisposedException

This object has been disposed.

Implements

IDisposable
IAsyncDisposable

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.GetUserData<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
ExpressionBuilder.Const<T>(T)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾