HostingEnvironment.QueueBackgroundWorkItem HostingEnvironment.QueueBackgroundWorkItem HostingEnvironment.QueueBackgroundWorkItem Method

Definition

[Supported in the .NET Framework 4.5.2 and later versions]

Schedules a task which can run in the background, independent of any request.

This overloaded method doesn’t flow the ExecutionContext or SecurityContext from the caller to the callee. Therefore, members of those objects, such as the CurrentPrincipal property, will not flow from the caller to the callee.

Overloads

QueueBackgroundWorkItem(Action<CancellationToken>) QueueBackgroundWorkItem(Action<CancellationToken>) QueueBackgroundWorkItem(Action<CancellationToken>)

[Supported in the .NET Framework 4.5.2 and later versions]

Schedules a task which can run in the background, independent of any request.

QueueBackgroundWorkItem(Func<CancellationToken,Task>) QueueBackgroundWorkItem(Func<CancellationToken,Task>) QueueBackgroundWorkItem(Func<CancellationToken,Task>)

[Supported in the .NET Framework 4.5.2 and later versions]

Schedules a task which can run in the background, independent of any request.

QueueBackgroundWorkItem(Action<CancellationToken>) QueueBackgroundWorkItem(Action<CancellationToken>) QueueBackgroundWorkItem(Action<CancellationToken>)

[Supported in the .NET Framework 4.5.2 and later versions]

Schedules a task which can run in the background, independent of any request.

public:
 static void QueueBackgroundWorkItem(Action<System::Threading::CancellationToken> ^ workItem);
public static void QueueBackgroundWorkItem (Action<System.Threading.CancellationToken> workItem);
Public Shared Sub QueueBackgroundWorkItem (workItem As Action(Of CancellationToken))
Parameters
workItem
Action<CancellationToken>

A unit of execution.

Remarks

Differs from a normal ThreadPool work item in that ASP.NET can keep track of how many work items registered through this API are currently running, and the ASP.NET runtime will try to delay AppDomain shutdown until these work items have finished executing. This API cannot be called outside of an ASP.NET-managed AppDomain. The provided CancellationToken will be signaled when the application is shutting down.

QueueBackgroundWorkItem takes a Task-returning callback; the work item will be considered finished when the callback returns.

QueueBackgroundWorkItem(Func<CancellationToken,Task>) QueueBackgroundWorkItem(Func<CancellationToken,Task>) QueueBackgroundWorkItem(Func<CancellationToken,Task>)

[Supported in the .NET Framework 4.5.2 and later versions]

Schedules a task which can run in the background, independent of any request.

public:
 static void QueueBackgroundWorkItem(Func<System::Threading::CancellationToken, System::Threading::Tasks::Task ^> ^ workItem);
public static void QueueBackgroundWorkItem (Func<System.Threading.CancellationToken,System.Threading.Tasks.Task> workItem);
Public Shared Sub QueueBackgroundWorkItem (workItem As Func(Of CancellationToken, Task))
Parameters
workItem
Func<CancellationToken,Task>

A unit of execution.

Remarks

Differs from a normal ThreadPool work item in that ASP.NET can keep track of how many work items registered through this API are currently running, and the ASP.NET runtime will try to delay AppDomain shutdown until these work items have finished executing. This API cannot be called outside of an ASP.NET-managed AppDomain. The provided CancellationToken will be signaled when the application is shutting down.

QueueBackgroundWorkItem takes a Task-returning callback; the work item will be considered finished when the returned Task transitions to a terminal state.

Applies to