Using a Custom Task Scheduler

The task scheduler is the point at which tasks and threads meet, and it is responsible for assigning threads to execute your Tasks and deciding how many Tasks will be executed in parallel and in which order.

As Chapter 1 explained, the TPL is built on the foundation of the classic threading features, and you have to understand these to build a custom scheduler. I am not going to explain the classic features in this book, but I will show you how to use them to create a custom scheduler.

This is an advanced topic, and you don't need to worry if you don't know how to use the classic threads or can't follow the explanation in this section. You can skip this section and still write effective parallel programs, because the .NET Framework's default scheduler is exceptionally sophisticated. In fact, my advice is to use the default scheduler and not implement a custom replacement. It is possible that you will be able to squeeze a little more performance out of your program with a custom scheduler, but the default scheduler is very competent, and any performance gain is likely to be marginal and offset by the need to test and maintain it for every platform to which your application is deployed.

0 0

Post a comment