Using the thread pool in Windows Runtime apps

Applies to Windows and Windows Phone

The topics in this section show how your app can use the thread pool to do parallel work.

Your app can use the thread pool to accomplish work asynchronously in parallel threads. The thread pool manages a set of threads and uses a queue to assign work items to threads as they become available. The thread pool is similar to the asynchronous programming patterns available in the Windows Runtime because it can be used to accomplish extended work without blocking the UI, but the thread pool offers more control than the asynchronous programming patterns and you can use it to complete multiple work items in parallel. You can use the thread pool to:

  • Submit work items, control their priority, and cancel work items.

  • Schedule work items using timers and periodic timers.

  • Set aside resources for critical work items.

  • Run work items in response to named events and semaphores.

The thread pool is more efficient than managing threads individually because it reduces the overhead of creating and destroying threads. The thread pool has advantages over app-based thread management systems because it runs at the OS level. The means it has access to optimize threads across multiple CPU cores, and it can balance thread resources between apps docked side-by-side and when background tasks are running. Using the built-in thread pool is convenient because you focus on writing code that accomplishes a task instead of the mechanics of thread management.

In this section

TopicDescription

Quickstart: Submitting a work item to the thread pool

Learn how to do work in a separate thread by submitting a work item to the thread pool.

How to submit a work item using a timer

Learn how to create a work item that runs after a timer elapses.

How to create a periodic work item

Learn how to create a work item that repeats periodically.

How to create and use pre-allocated work items

Learn how to guarantee the availability of a work item by allocating resources for it ahead of time.

How to respond to named events and semaphores

Learn how to run thread pool work items in response to named events and semaphores.

How to use functions as work item delegates

Learn how to use functions (and function objects) as work item delegates.

Best practices for using the thread pool

This topic describes best practices for working with the thread pool.

 

 

 

Show:
© 2014 Microsoft