Created
February 20, 2017 03:19
-
-
Save droyad/eda4750bca183815a0dd09b5097f2276 to your computer and use it in GitHub Desktop.
ThreadPool Throttle
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
// 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