Table of Contents

AsyncActionFactory Class

Definition

Namespace
Cuemon.Threading
Assemblies
Cuemon.Threading.dll
Source
src/Cuemon.Threading/AsyncActionFactory.cs

Provides access to factory methods for creating AsyncActionFactory<TTuple> instances that encapsulate a Task based function delegate with a variable amount of generic arguments.

public static class AsyncActionFactory
Inheritance
AsyncActionFactory

Examples

AsyncActionFactory provides factory methods for creating deferred asynchronous actions with zero or more typed arguments, executed via ExecuteMethodAsync. This example creates an action that prints "Async operation executed" and another with a string argument that logs "Hello from async action" after a 10ms delay, then invokes each with CancellationToken.None. Key setup includes using AsyncActionFactory.Create with a lambda and passing arguments separately so the factory handles lifetime and error propagation. Console output confirms both actions execute successfully, with the parameterized action receiving and printing the supplied message.

using System;
using System.Threading;
using System.Threading.Tasks;
using Cuemon.Threading;

namespace Cuemon.Threading;

public class AsyncActionFactoryExample
{
    public async Task DemonstrateAsync()
    {
        var factory = AsyncActionFactory.Create(ct =>
        {
            Console.WriteLine("Async operation executed");
            return Task.CompletedTask;
        });
        await factory.ExecuteMethodAsync(CancellationToken.None);

        var factoryWithArg = AsyncActionFactory.Create(async (string msg, CancellationToken ct) =>
        {
            await Task.Delay(10, ct);
            Console.WriteLine(msg);
        }, "Hello from async action");
        await factoryWithArg.ExecuteMethodAsync(CancellationToken.None);
    }
}

Methods

Name Description
Create(Func<CancellationToken, Task>)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method.

Create<T>(Func<T, CancellationToken, Task>, T)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and one generic argument.

Create<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, CancellationToken, Task>, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and ten generic arguments.

Create<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, CancellationToken, Task>, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and eleven generic arguments.

Create<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, CancellationToken, Task>, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and twelfth generic arguments.

Create<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, CancellationToken, Task>, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and thirteen generic arguments.

Create<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, CancellationToken, Task>, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and fourteen generic arguments.

Create<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, CancellationToken, Task>, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and fifteen generic arguments.

Create<T1, T2>(Func<T1, T2, CancellationToken, Task>, T1, T2)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and two generic arguments.

Create<T1, T2, T3>(Func<T1, T2, T3, CancellationToken, Task>, T1, T2, T3)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and three generic arguments.

Create<T1, T2, T3, T4>(Func<T1, T2, T3, T4, CancellationToken, Task>, T1, T2, T3, T4)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and four generic arguments.

Create<T1, T2, T3, T4, T5>(Func<T1, T2, T3, T4, T5, CancellationToken, Task>, T1, T2, T3, T4, T5)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and five generic arguments.

Create<T1, T2, T3, T4, T5, T6>(Func<T1, T2, T3, T4, T5, T6, CancellationToken, Task>, T1, T2, T3, T4, T5, T6)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and six generic arguments.

Create<T1, T2, T3, T4, T5, T6, T7>(Func<T1, T2, T3, T4, T5, T6, T7, CancellationToken, Task>, T1, T2, T3, T4, T5, T6, T7)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and seven generic arguments.

Create<T1, T2, T3, T4, T5, T6, T7, T8>(Func<T1, T2, T3, T4, T5, T6, T7, T8, CancellationToken, Task>, T1, T2, T3, T4, T5, T6, T7, T8)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and eight generic arguments.

Create<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, CancellationToken, Task>, T1, T2, T3, T4, T5, T6, T7, T8, T9)

Creates a new AsyncActionFactory<TTuple> instance encapsulating the specified method and nine generic arguments.