Skip to content

Files

Latest commit

97fbc73 · Dec 16, 2024

History

History
34 lines (24 loc) · 956 Bytes

README.md

File metadata and controls

34 lines (24 loc) · 956 Bytes

ru

Pool Infinite Tasks C#

NuGet version (PoolInfiniteTasks)

The solution allows you to create a pool to perform endless tasks and recreate them in case of failure.

Usage example

using PoolInfiniteTasks;

var cts = new CancellationTokenSource();

cts.CancelAfter(5000);

Func<CancellationToken, Task> myTaskFactory = (cancellationToken) =>
{
    return Task.Run(async () =>
    {
        while (!cancellationToken.IsCancellationRequested)
        {
            // Any of your logic            
            await Task.Delay(1000, cancellationToken);
            Console.WriteLine("Success");
            throw new Exception("test");
        }
    }, cancellationToken);
};

await new PoolInfiniteTasksManager(myTaskFactory, 3).Run(cts.Token);