HostingEnvironment.QueueBackgroundWorkItem Method (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.

Namespace:   System.Web.Hosting
Assembly:  System.Web (in System.Web.dll)

[SecurityPermissionAttribute(SecurityAction.LinkDemand, Unrestricted = true)]
public static void QueueBackgroundWorkItem(
	Action<CancellationToken> workItem
)

Parameters

workItem
Type: System.Action<CancellationToken>

A unit of execution.

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.

.NET Framework
Available since 4.5.2
Return to top
Show: