Skip to content

BackgroundTasks: Start you background task

ronimizy edited this page Jan 27, 2024 · 2 revisions

Use IBackgroundTaskRunner type and it's StartBackgroundTask builder property to run your background task.
You have to specify metadata, execution metadata and handler of type IBackgroundTask<,,,> configured with specified metadata and execution metadata types.

BackgroundTaskId backgroundTaskId = await _runner
    .StartBackgroundTask
    .WithMetadata(EmptyMetadata.Value)
    .WithExecutionMetadata(EmptyExecutionMetadata.Value)
    .RunWithAsync<SampleBackgroundTask>(default);

RunAsync method will return BackgroundTaskId object, you can store it to work with started task in the future.