O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Use a Pool of Threads

Problem

You need to create an unbounded number of threads without degrading performance.

Solution

Use the ThreadPool class to map a large number of tasks to a fixed number of reusable threads.

Discussion

The System.Threading.ThreadPool class allows you to execute code using a pool of threads provided by the common language runtime. Using this pool simplifies your code, and it can improve performance, particularly if you use a large number of short-lived threads. The ThreadPool class avoids the overhead of continually creating and destroying threads by using a pool of reusable threads. You use the ThreadPool class to queue a task, and the task is processed on the first available thread. The ThreadPool class is capped at 25 threads ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required