I recently started working on trying to massage a website for archiving purposes, and I thought it would be nice if several web requests worked asynchronously to speed things up (10,000,000 pages, certainly a lot for archiving), and therefore I ventured into the stern mistress of parallelism, after three minutes I begin to wonder why the tasks that I create (via Task.Factory.StartNew ) are โcloggedโ.
Annoyed and intrigued, I decided to check this to make sure that it was not just the result of circumstances, so I created a new console project in VS2012 and created this:
static void Main(string[] args) { for (int i = 0; i < 10; i++) { int i2 = i + 1; Stopwatch t = new Stopwatch(); t.Start(); Task.Factory.StartNew(() => { t.Stop(); Console.ForegroundColor = ConsoleColor.Green; //Note that the other tasks might manage to write their lines between these colour changes messing up the colours. Console.WriteLine("Task " + i2 + " started after " + t.Elapsed.Seconds + "." + t.Elapsed.Milliseconds + "s"); Thread.Sleep(5000); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Task " + i2 + " finished"); }); } Console.ReadKey(); }
What at startup came up with this result:

As you can see, the first four tasks begin with a quick sequence with a time of ~ 0.27, however, after that the tasks begin to increase dramatically in the time it takes to start them.
Why is this happening and what can I do to fix or circumvent this limitation?
c # asynchronous parallel-processing task
AlphaDelta
source share