AsyncOptions Class
Definition
- Assemblies
- Cuemon.Kernel.dll
Specifies options that is related to asynchronous operations.
public class AsyncOptions : IAsyncOptions, IParameterObject
- Inheritance
-
AsyncOptions
- Implements
- Derived
Examples
The following example demonstrates how to configure AsyncOptions to provide a cancellation token for asynchronous operations.
using System;
using System.Threading;
using System.Threading.Tasks;
using Cuemon.Threading;
namespace Contoso.BackgroundJobs;
public sealed class AsyncOptionsExample
{
public static async Task RunAsync()
{
var defaults = new AsyncOptions();
Console.WriteLine(defaults.CancellationToken == CancellationToken.None);
using var cts = new CancellationTokenSource();
var options = new AsyncOptions
{
CancellationTokenProvider = () => cts.Token
};
cts.Cancel();
try
{
await Task.Delay(10, options.CancellationToken);
}
catch (OperationCanceledException)
{
Console.WriteLine("Cancelled as expected.");
}
}
}
Constructors
| Name | Description |
|---|---|
| AsyncOptions() | Initializes a new instance of the AsyncOptions class. |
Properties
| Name | Description |
|---|---|
| CancellationToken | Gets or sets the cancellation token of an asynchronous operations. |
| CancellationTokenProvider | Gets or sets the function delegate that is invoked when a CancellationToken is requested. |