While playing with the Parallel library, I came across unexpected results from Task Factory.
Assumption: Task Factory will process calls randomly
Result: Sequential processing every single time (whether the same function or different functions)
static void Do(string test)
{
Console.WriteLine("testttttt " + test);
}
static void Main(string[] args)
{
Task.Factory.StartNew(() =>
{
Do("1"); Do("2"); Do("3"); Do("4"); Do("5");
Do("1"); Do("2"); Do("3"); Do("4"); Do("5");
Do("1"); Do("2"); Do("3"); Do("4"); Do("5");
});
Console.ReadKey();
}
The following code produces random results:
Task.Factory.StartNew(() =>
{
Do("1"); Do("2"); Do("3"); Do("4"); Do("5");
});
Task.Factory.StartNew(() =>
{
Do("1"); Do("2"); Do("3"); Do("4"); Do("5");
});
Task.Factory.StartNew(() =>
{
Do("1"); Do("2"); Do("3"); Do("4"); Do("5");
});
Why the first example always produce sequential results and should this be taken for granted everything time?