Table of Contents

Class BackgroundTaskRunner

Namespace
Excalibur.Dispatch.Threading
Assembly
Excalibur.Dispatch.dll

Utility class for running detached background tasks.

public static class BackgroundTaskRunner
Inheritance
BackgroundTaskRunner
Inherited Members

Methods

RunDetachedInBackground(Func<CancellationToken, Task>, CancellationToken, Func<Exception, Task>?, ILogger?)

Runs a task in the background without waiting for completion.

public static void RunDetachedInBackground(Func<CancellationToken, Task> taskFactory, CancellationToken cancellationToken, Func<Exception, Task>? onError = null, ILogger? logger = null)

Parameters

taskFactory Func<CancellationToken, Task>

Factory function that creates the task to run.

cancellationToken CancellationToken

Cancellation token for the background task.

onError Func<Exception, Task>

Optional error handler for exceptions.

logger ILogger

Optional logger for unhandled exceptions.

Remarks

This method starts a task on the thread pool and does not wait for completion. Exceptions are handled according to the provided error handler or logged.

DECOUPLED IS NOT DISCARDED. The work is registered so a graceful host shutdown drains it within the host's own shutdown budget. That makes it best-effort WITHIN THE PROCESS — it does not make it durable: an abrupt termination, an out-of-memory kill or a node eviction still loses it, which is inherent to running in-process rather than a gap left open. Work that must survive a crash belongs in the outbox.