HostingEnvironment.QueueBackgroundWorkItem 方法

定義

排程可在背景中執行的工作,不受任何要求影響。Schedules a task which can run in the background, independent of any request.

此多載方法不會讓 ExecutionContextSecurityContext 從呼叫者流動至被呼叫者。This overloaded method doesn't flow the ExecutionContext or SecurityContext from the caller to the callee. 因此,這些物件的成員 (例如 CurrentPrincipal 屬性) 都不會從呼叫者流入被呼叫者。Therefore, members of those objects, such as the CurrentPrincipal property, will not flow from the caller to the callee.

多載

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

參數

workItem
Action<CancellationToken>

執行單位。A unit of execution.

備註

與一般 ThreadPool 工作專案不同的是,該 ASP.NET 可以追蹤目前正在執行此 API 註冊的工作專案數,而 ASP.NET 執行時間會嘗試延遲 AppDomain 關閉,直到這些工作專案執行完成為止。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. 此 API 無法在 ASP.NET 管理的 AppDomain 之外呼叫。This API cannot be called outside of an ASP.NET-managed AppDomain. 當應用程式關閉時,所提供的 CancellationToken 將會收到信號。The provided CancellationToken will be signaled when the application is shutting down.

QueueBackgroundWorkItem 取得傳回工作的回呼;工作專案會在回呼傳回時被視為已完成。QueueBackgroundWorkItem takes a Task-returning callback; the work item will be considered finished when the callback returns.

適用於

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

參數

workItem
Func<CancellationToken,Task>

執行單位。A unit of execution.

備註

與一般 ThreadPool 工作專案不同的是,該 ASP.NET 可以追蹤目前正在執行此 API 註冊的工作專案數,而 ASP.NET 執行時間會嘗試延遲 AppDomain 關閉,直到這些工作專案執行完成為止。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. 此 API 無法在 ASP.NET 管理的 AppDomain 之外呼叫。This API cannot be called outside of an ASP.NET-managed AppDomain. 當應用程式關閉時,所提供的 CancellationToken 將會收到信號。The provided CancellationToken will be signaled when the application is shutting down.

QueueBackgroundWorkItem 取得傳回工作的回呼;當傳回的工作轉換成終止狀態時,工作專案就會被視為已完成。QueueBackgroundWorkItem takes a Task-returning callback; the work item will be considered finished when the returned Task transitions to a terminal state.

適用於