This recipe will show you how a thread pool works with many asynchronous operations and how it is different from creating many separate threads.
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
.
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...