Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Threading.​CancellationTokenSource
Assembly: System.Runtime
Inheritance: object → CancellationTokenSource
Signals to a <see cref="T:System.Threading.CancellationToken" /> that it should be canceled.
Properties
public
bool
IsCancellationRequested
Gets whether cancellation has been requested for this <see cref="T:System.Threading.CancellationTokenSource" /> .
public
CancellationToken
Token
Gets the <see cref="T:System.Threading.CancellationToken" /> associated with this <see cref="T:System.Threading.CancellationTokenSource" /> .
Methods
public
void
Cancel​()
Communicates a request for cancellation.
public
void
Cancel​(bool throwOnFirstException)
throwOnFirstException
<see langword="true" /> if exceptions should immediately propagate; otherwise, <see langword="false" /> .
Communicates a request for cancellation, and specifies whether remaining callbacks and cancelable operations should be processed if an exception occurs.
public
void
CancelAfter​(int millisecondsDelay)
millisecondsDelay
The time span to wait before canceling this <see cref="T:System.Threading.CancellationTokenSource" /> .
Schedules a cancel operation on this <see cref="T:System.Threading.CancellationTokenSource" /> after the specified number of milliseconds.
public
void
CancelAfter​(TimeSpan delay)
delay
The time span to wait before canceling this <see cref="T:System.Threading.CancellationTokenSource" /> .
Schedules a cancel operation on this <see cref="T:System.Threading.CancellationTokenSource" /> after the specified time span.
public
Task
CancelAsync​() Returns A task that will complete after cancelable operations and callbacks registered with the associated <see cref="T:System.Threading.CancellationToken" /> have completed.
Communicates a request for cancellation asynchronously.
public
void
Dispose​()
Releases all resources used by the current instance of the <see cref="T:System.Threading.CancellationTokenSource" /> class.
protected
void
Dispose​(bool disposing)
disposing
<see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
Releases the unmanaged resources used by the <see cref="T:System.Threading.CancellationTokenSource" /> class and optionally releases the managed resources.
public
bool
TryReset​() Returns <see langword="true" /> if the <see cref="T:System.Threading.CancellationTokenSource" /> has not had cancellation requested and could have its state reset to be reused for a subsequent operation; otherwise, <see langword="false" /> .
Attempts to reset the <see cref="T:System.Threading.CancellationTokenSource" /> to be used for an unrelated operation.
public
bool
Equals​(object obj)
Inherited from object
obj
The object to compare with the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
Determines whether the specified object is equal to the current object.
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
int
GetHashCode​()
Inherited from object
Returns A hash code for the current object.
Serves as the default hash function.
public
Type
GetType​()
Inherited from object
Returns The exact runtime type of the current instance.
Gets the <see cref="T:System.Type" /> of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Returns A shallow copy of the current <see cref="T:System.Object" /> .
Creates a shallow copy of the current <see cref="T:System.Object" /> .
public
string
ToString​()
Inherited from object
Returns A string that represents the current object.
Returns a string that represents the current object.