I got a question for .NET 4.0 TPL programmers. I created this TPL and ThreadPool stress tester where i run X tests, each test executes Y number of tasks, when finishes, it continues to the next test.
The issue i have is that if a single test starts 100 tasks, the following test will add more tasks and so on, leaving me with huge amount of threads.
(The thread count i have is taken from Resource Monitor).
pseudo code:
while (tasksLeftToRun != 0)
{
var nextTask = new Task(new Action(()=>
{
Thread.Sleep(20);
}), cancellationToken);
nextTask.Start();
nextTask.ContinueWith((t) =>
{
//...
},TaskScheduler.Default);
tasksLeftToRun--;
}
About 15 seconds after the application finishes with the tests, the thread count drops to ~7.
Thanks!