O'Reilly logo

C# 7 and .NET Core Cookbook by Dirk Strauss

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

How to do it...

  1. Create a new method called IncreaseThreadPoolSize() in the Demo class.
  1. Start by adding the code to read the number of processors on the current machine using Environment.ProcessorCount:
        public class Demo        {          public void IncreaseThreadPoolSize()          {             int numberOfProcessors = Environment.ProcessorCount;             WriteLine($"Processor Count = {numberOfProcessors}");          }        }
  1. Next, we retrieve the maximum and minimum threads available in the thread pool:
        int maxworkerThreads;         int maxconcurrentActiveRequests;         int minworkerThreads;         int minconcurrentActiveRequests;         ThreadPool.GetMinThreads(out minworkerThreads,           out  minconcurrentActiveRequests);        WriteLine($"ThreadPool minimum Worker = {minworkerThreads}  and minimum Requests = {minconcurrentActiveRequests}"); ...

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