Skip to content

Instantly share code, notes, and snippets.

@droyad
Created February 20, 2017 03:19
Show Gist options
  • Save droyad/eda4750bca183815a0dd09b5097f2276 to your computer and use it in GitHub Desktop.
Save droyad/eda4750bca183815a0dd09b5097f2276 to your computer and use it in GitHub Desktop.
ThreadPool Throttle
// Output
// 8
// 9
// 10
// 11
// 12
// 13
// 14
// 15
// 16
// 59
// 127
// 323
// 447
// 551
// 642
// 720
// 787
// 848
static void Main(string[] args)
{
int n = 0;
var s = new ManualResetEventSlim();
for (int x = 0; x < 1200; x++)
{
Task.Run(() =>
{
Interlocked.Increment(ref n);
s.Wait(TimeSpan.FromDays(1));
});
}
while (true)
{
Console.WriteLine(n);
if (n > 15)
ThreadPool.SetMinThreads(1000, 1000);
Thread.Sleep(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment