Preallocated​Work​Item Preallocated​Work​Item Preallocated​Work​Item Class

Definition

A preallocated work item is constructed in advance of its submission to the thread pool, ensuring that the work item is constructed so that it can be submitted to the thread pool when necessary. For example, a PreallocatedWorkItem can be created in case it is needed for a resource deallocation routine, since the resource deallocation routine may be called in circumstances when not enough resources would be available to create the work item.

Note

The ThreadPool API is supported for desktop as well as Windows Store apps.

public sealed class PreallocatedWorkItem : IPreallocatedWorkItempublic sealed class PreallocatedWorkItem : IPreallocatedWorkItemPublic NotInheritable Class PreallocatedWorkItem Implements IPreallocatedWorkItem
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Constructors

PreallocatedWorkItem(WorkItemHandler) PreallocatedWorkItem(WorkItemHandler) PreallocatedWorkItem(WorkItemHandler)

Initializes a new work item with a WorkItemHandler delegate, allocating resources for the work item in advance.

public PreallocatedWorkItem(WorkItemHandler handler)public PreallocatedWorkItem(WorkItemHandler handler)Public Sub New(handler As WorkItemHandler)
Parameters
handler
WorkItemHandler WorkItemHandler WorkItemHandler

Indicates the method that the preallocated work item will run.

Attributes

Remarks

In C++, make sure that methods used as WorkItemHandler delegates exhibit agile threading model behavior. Calling a non-agile method from a work item will cause a deadlock to occur.

PreallocatedWorkItem(WorkItemHandler, WorkItemPriority) PreallocatedWorkItem(WorkItemHandler, WorkItemPriority) PreallocatedWorkItem(WorkItemHandler, WorkItemPriority)

Initializes a new work item with a WorkItemHandler delegate, allocating resources for the work item in advance, and specifies the priority of the work item relative to other work items in the thread pool.

public PreallocatedWorkItem(WorkItemHandler handler, WorkItemPriority priority)public PreallocatedWorkItem(WorkItemHandler handler, WorkItemPriority priority)Public Sub New(handler As WorkItemHandler, priority As WorkItemPriority)
Parameters
handler
WorkItemHandler WorkItemHandler WorkItemHandler

Indicates the method that the preallocated work item will run.

priority
WorkItemPriority WorkItemPriority WorkItemPriority

The priority of the work item relative to other work items in the thread pool. The value of this parameter can be Low, Normal, or High.

Attributes

Remarks

See the remarks section of the PreallocatedWorkItem(WorkItemHandler) overload.

PreallocatedWorkItem(WorkItemHandler, WorkItemPriority, WorkItemOptions) PreallocatedWorkItem(WorkItemHandler, WorkItemPriority, WorkItemOptions) PreallocatedWorkItem(WorkItemHandler, WorkItemPriority, WorkItemOptions)

Initializes a new work item with a WorkItemHandler delegate, allocating resources for the work item in advance, and specifies the priority of the work item relative to other work items in the thread pool. Also specifies how the thread pool will allocate processor time for the work item.

public PreallocatedWorkItem(WorkItemHandler handler, WorkItemPriority priority, WorkItemOptions options)public PreallocatedWorkItem(WorkItemHandler handler, WorkItemPriority priority, WorkItemOptions options)Public Sub New(handler As WorkItemHandler, priority As WorkItemPriority, options As WorkItemOptions)
Parameters
handler
WorkItemHandler WorkItemHandler WorkItemHandler

Indicates the method that the preallocated work item will run.

priority
WorkItemPriority WorkItemPriority WorkItemPriority

The priority of the work item relative to other work items in the thread pool. The value of this parameter can be Low, Normal, or High.

options
WorkItemOptions WorkItemOptions WorkItemOptions

If this parameter is set to TimeSliced, the work item runs simultaneously with other time-sliced work items, with each work item receiving a share of processor time. If this parameter is set to None, the work item runs when a worker thread becomes available.

Attributes

Remarks

See the remarks section of the PreallocatedWorkItem(WorkItemHandler) overload.

Methods

RunAsync() RunAsync() RunAsync()

Submits the preallocated work item to the thread pool, without requiring any additional resources to be allocated.

public IAsyncAction RunAsync()public IAsyncAction RunAsync()Public Function RunAsync() As IAsyncAction
Returns

Provides access to the running IAsyncAction that was previously constructed and given the necessary resource allocation.

Attributes

Remarks

For information about how IAsyncAction applies to work items, see Windows.System.Threading.RunAsync.