Class TimeoutSource
Represents reusable timeout tracker that is linked to the root cancellation token.
Inherited Members
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 SourceTimeoutSource(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 SourceIsCanceled
Gets a value indicating that this source is canceled by the root token.
Declaration
public bool IsCanceled { get; }
Property Value
Type | Description |
---|---|
bool |
IsTimedOut
Gets a value indicating that this source is timed out.
Declaration
public bool IsTimedOut { get; }
Property Value
Type | Description |
---|---|
bool |
RootToken
Gets the root token passed to TimeoutSource(TimeProvider, CancellationToken) constructor.
Declaration
public CancellationToken RootToken { get; }
Property Value
Type | Description |
---|---|
CancellationToken |
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 SourceDispose()
Disposes the provider.
Declaration
public void Dispose()
DisposeAsync()
Disposes the provider asynchronously.
Declaration
public ValueTask DisposeAsync()
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous state of the operation. |
~TimeoutSource()
Declaration
protected ~TimeoutSource()
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. |
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. |