Property cancellationToken
cancellationToken
A cancellation token used across the Scripting subsystem to manage the cancellation of long-running operations.
Declaration
public CancellationToken cancellationToken { get; set; }
Property Value
Type | Description |
---|---|
CancellationToken |
Remarks
This token should be passed to and checked in any potentially long-running or asynchronous operations within the Scripting subsystem. Utilizing this token in operations such as loops, asynchronous method calls, and any task that may exceed a trivial execution time is critical for ensuring that the system remains responsive and able to cancel execution or operations as required.
Failure to use this token in long-running operations may result in the inability of the system to terminate tasks promptly, potentially leading to unresponsive behavior or resource leaks. It is imperative for the stability and reliability of the system that any method or operation that could be subject to cancellation or that may run longer than expected respects this cancellation token.
Example usage in a while loop:
while (!cancellationToken.IsCancellationRequested)
{
// Perform operation
await Task.Delay(1000, cancellationToken); // Always pass cancellationToken to async operations
}
Always check IsCancellationRequested property or pass the token directly to APIs that accept a CancellationToken to ensure operations can be cancelled in line with the system's requirements.