In your example, the methods will be definitely sequential, since the .NET console will synchronize calls from different threads .
, , Thread.ManagedThreadID Environment.CurrentManagedThreadId ( .NET 4.5)
class Program
{
static void Main(string[] args)
{
Parallel.For(0, 10, i => DoSomething(i));
Console.ReadLine();
Parallel.For(0, 10, new ParallelOptions{
MaxDegreeOfParallelism = 2
}, i => DoSomething(i));
Console.ReadLine();
}
static void DoSomething(int par)
{
int i = Environment.CurrentManagedThreadId;
Thread.Sleep(200);
Console.WriteLine("Test: "+ par.ToString() +
", Thread :" + i.ToString());
}
}
Thread.Sleep, , , , , , .
( ) , , .
, , , . , , , , . , (, ) .
, , - , , . parallelism, .