Created
July 26, 2017 16:31
-
-
Save Entroper/d9b517c2230a892a1c87c9751272e55d to your computer and use it in GitHub Desktop.
Shows how the .NET Threadpool creates new threads.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine(GetActiveThreads()); | |
while (true) | |
{ | |
Thread.Sleep(100); | |
Task.Run(() => Thread.Sleep(TimeSpan.FromMinutes(10))); | |
Console.WriteLine(GetActiveThreads()); | |
} | |
} | |
static int GetActiveThreads() | |
{ | |
ThreadPool.GetMaxThreads(out int maxWorker, out int maxIo); | |
ThreadPool.GetAvailableThreads(out int worker, out int io); | |
return maxWorker - worker; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment