AsyncRunOptions Class
Definition
- Assemblies
- Cuemon.Kernel.dll
Provides options that are related to asynchronous run operations.
public class AsyncRunOptions : AsyncOptions, IAsyncOptions, IValidatableParameterObject, IParameterObject
- Inheritance
-
AsyncRunOptions
- Implements
- Inherited Members
Examples
The following example demonstrates how to use
using System;
using System.Threading;
using Cuemon.Threading;
namespace MyApp.Examples;
public class AsyncRunOptionsExample
{
public void Demonstrate()
{
var options = new AsyncRunOptions
{
Timeout = TimeSpan.FromSeconds(30),
Delay = TimeSpan.FromMilliseconds(500),
MaximumAttempts = 3
};
Console.WriteLine(options.Timeout); // 00:00:30
Console.WriteLine(options.Delay); // 00:00:00.5000000
Console.WriteLine(options.MaximumAttempts); // 3
// Use with cancellation support
var withCancellation = new AsyncRunOptions
{
Timeout = TimeSpan.FromSeconds(10),
CancellationToken = new CancellationTokenSource(5000).Token
};
// Zero-delay retries require an explicit attempt limit
var zeroDelay = new AsyncRunOptions
{
Timeout = TimeSpan.FromSeconds(1),
Delay = TimeSpan.Zero,
MaximumAttempts = 3
};
Console.WriteLine(zeroDelay.MaximumAttempts); // 3
// Defaults: timeout 5s, delay 100ms
var defaults = new AsyncRunOptions();
Console.WriteLine(defaults.Timeout); // 00:00:05
Console.WriteLine(defaults.Delay); // 00:00:00.1000000
Console.WriteLine(defaults.MaximumAttempts); // 0
Console.WriteLine(withCancellation.CancellationToken.CanBeCanceled); // True
}
}
Constructors
| Name | Description |
|---|---|
| AsyncRunOptions() | Initializes a new instance of the AsyncRunOptions class. |
Properties
| Name | Description |
|---|---|
| Delay | Gets or sets the configured delay between unsuccessful asynchronous operation attempts. |
| MaximumAttempts | Gets or sets the maximum number of total invocations, including the initial invocation. |
| Timeout | Gets or sets the total retry window for the asynchronous operation. |
Methods
| Name | Description |
|---|---|
| ValidateOptions() | Determines whether the public read-write properties of this instance are in a valid state. |