Table of Contents

TransientOperation Class

Definition

Namespace
Cuemon.Resilience
Assemblies
Cuemon.Resilience.dll
Source
src/Cuemon.Resilience/TransientOperation.cs

Provides a set of static methods that enable developers to make their applications more resilient by adding robust transient fault handling logic ideal for temporary condition such as network connectivity issues or service unavailability.

public static class TransientOperation
Inheritance
TransientOperation

Examples

The following example shows how to execute an HTTP request with retry logic using TransientOperation. It configures three retry attempts with exponential backoff and prints the response length on success.

using System;
using System.Net.Http;
using Cuemon.Resilience;

namespace Cuemon.Resilience;

public class TransientOperationExample
{
    public void Demonstrate()
    {
        var result = TransientOperation.WithFunc(() =>
        {
            using var client = new HttpClient();
            return client.GetStringAsync("https://example.com").Result;
        }, options =>
        {
            options.RetryAttempts = 3;
            options.RetryStrategy = attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt));
        });

        Console.WriteLine($"Response length: {result.Length}");
    }
}

Properties

Name Description
FaultCallback

Gets or sets the callback delegate that is invoked when a transient fault occurs.

Methods

Name Description
WithAction(Action, Action<TransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithActionAsync(Func<CancellationToken, Task>, Action<AsyncTransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithActionAsync<T>(Func<T, CancellationToken, Task>, T, Action<AsyncTransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithActionAsync<T1, T2>(Func<T1, T2, CancellationToken, Task>, T1, T2, Action<AsyncTransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithActionAsync<T1, T2, T3>(Func<T1, T2, T3, CancellationToken, Task>, T1, T2, T3, Action<AsyncTransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithActionAsync<T1, T2, T3, T4>(Func<T1, T2, T3, T4, CancellationToken, Task>, T1, T2, T3, T4, Action<AsyncTransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithActionAsync<T1, T2, T3, T4, T5>(Func<T1, T2, T3, T4, T5, CancellationToken, Task>, T1, T2, T3, T4, T5, Action<AsyncTransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithAction<T>(Action<T>, T, Action<TransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithAction<T1, T2>(Action<T1, T2>, T1, T2, Action<TransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithAction<T1, T2, T3>(Action<T1, T2, T3>, T1, T2, T3, Action<TransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithAction<T1, T2, T3, T4>(Action<T1, T2, T3, T4>, T1, T2, T3, T4, Action<TransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithAction<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5>, T1, T2, T3, T4, T5, Action<TransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithFuncAsync<TResult>(Func<CancellationToken, Task<TResult>>, Action<AsyncTransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithFuncAsync<T, TResult>(Func<T, CancellationToken, Task<TResult>>, T, Action<AsyncTransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithFuncAsync<T1, T2, TResult>(Func<T1, T2, CancellationToken, Task<TResult>>, T1, T2, Action<AsyncTransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithFuncAsync<T1, T2, T3, TResult>(Func<T1, T2, T3, CancellationToken, Task<TResult>>, T1, T2, T3, Action<AsyncTransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithFuncAsync<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, CancellationToken, Task<TResult>>, T1, T2, T3, T4, Action<AsyncTransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithFuncAsync<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, CancellationToken, Task<TResult>>, T1, T2, T3, T4, T5, Action<AsyncTransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithFunc<TResult>(Func<TResult>, Action<TransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithFunc<T, TResult>(Func<T, TResult>, T, Action<TransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithFunc<T1, T2, TResult>(Func<T1, T2, TResult>, T1, T2, Action<TransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithFunc<T1, T2, T3, TResult>(Func<T1, T2, T3, TResult>, T1, T2, T3, Action<TransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithFunc<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, TResult>, T1, T2, T3, T4, Action<TransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.

WithFunc<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, TResult>, T1, T2, T3, T4, T5, Action<TransientOperationOptions>)

Repetitively executes the specified faultSensitiveMethod until the operation is successful, the amount of retry attempts has been reached, or a failed operation is not considered related to transient fault condition.