Delen via


Windows.System.Threading.Core Namespace

Creates work items that run in response to named events and semaphores. Also preallocates resources for work items that must be guaranteed the ability to run, even in circumstances of heavy (or full) resource allocation.

Note

The ThreadPool API is supported for desktop as well as UWP apps.

PreallocatedWorkItemWhen work items are created using ThreadPool.RunAsync, the work item is created and submitted as a single operation. This is acceptable for most scenarios, but it is sometimes necessary to set aside resources for a work item in advance.

The PreallocatedWorkItem class constructs a work item ahead of time, putting the work item "on standby" so that it can be submitted to the thread pool when it's needed. This is useful in circumstances where the resources available to your app are completely allocated before the work item is needed - for example, calling a deallocation routine that uses a work item. If a work item has already been allocated, the resource deallocation routine can still be called and the PreallocatedWorkItem can still be submitted to the thread pool even if all resources are already in use. Sometimes it is necessary to queue work items in response to named events or semaphores created by Win32 COM objects. You can run a Windows Runtime method in response to a named event or semaphore using a SignalNotifier object. This allows you to write Windows Runtime code that responds to events and signals sent using Win32 and COM for , provided that the event or semaphore has a name. For example, the SignalNotifier can be used to work with Win32 code that's being ported to a UWP app. ISignalableNotifierOccasionally it is not possible to know the name of an event or semaphore, but your app still needs to respond to it; for example legacy code, and some well-known events and semaphores, still use waitable handles instead of names. ISignalableNotifier allows you to create ISignalNotifier objects registered with waitable handles.

Note

Preallocated work items are only needed for apps that may use up all available resources, or that need to create work items for resource deallocation routines. Signal notifiers are only applicable to certain apps that use Win32 and COM for . If you don't need to use preallocation or signaling in your app, create work items by using Windows.System.Threading.

Classes

PreallocatedWorkItem

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 UWP apps.

SignalNotifier

Runs a method when an event or semaphore is signaled. A timeout value can also be specified, causing the delegate to run after the time span has elapsed if the named event does not occur (or if the semaphore does not reach a signaled state).

Note

The ThreadPool API is supported for desktop as well as UWP apps.

Delegates

SignalHandler

Represents a method that is called when a signal notifier's attached event or semaphore is signaled, or when the optional timeout value has elapsed (whichever comes first).