Editar

Compartir a través de


HostingEnvironment.QueueBackgroundWorkItem Method

Definition

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>)

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

QueueBackgroundWorkItem(Func<CancellationToken,Task>)

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

QueueBackgroundWorkItem(Action<CancellationToken>)

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);
static member QueueBackgroundWorkItem : Action<System.Threading.CancellationToken> -> unit
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.

Applies to

QueueBackgroundWorkItem(Func<CancellationToken,Task>)

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);
static member QueueBackgroundWorkItem : Func<System.Threading.CancellationToken, System.Threading.Tasks.Task> -> unit
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