ThreadPool

In all of the preceding examples, threads were explicitly created. In real-world scenarios, though, most of the time you should use a ThreadPool instead. A ThreadPool is a pool of threads. It starts out empty, and when your code requests a new thread from the pool, the pool will keep the thread around for the next time your code needs a thread again. The performance gains are impressive because a new thread need not be created most times because threads that are idling in the pool can be reused. Also, threads need not be destroyed immediately, which results in another performance gain. Finally, if an application were to create a large number of tasks, the ThreadPool would create a maximum of 25 threads[14] and queue all other work items ...

Get Microsoft® Mobile Development Handbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.