A thread pool and the degree of parallelism
This recipe will show you how a thread pool works with many asynchronous operations and how it is different from creating many separate threads.
Getting ready
To step into this recipe, you will need Visual Studio 2015. There are no other prerequisites. The source code for this recipe can be found in BookSamples\Chapter3\Recipe3
.
How to do it...
To learn how a thread pool works with many asynchronous operations and how it is different from creating many separate threads, perform the following steps:
Start Visual Studio 2015. Create a new C# console application project.
In the
Program.cs
file, add the followingusing
directives:using System; using System.Diagnostics; using System.Threading; using static System.Console; using static System.Threading.Thread;
Add the following code snippet below the
Main
method:static void UseThreads(int numberOfOperations) { using (var countdown = new CountdownEvent(numberOfOperations)) { WriteLine("Scheduling work...