I am going to create thread like this :
static void Main(string[] args)
{
Thread tr2 = new Thread(() =>
{
int a = 0;
Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId);
});
tr2.Start();
Console.ReadKey();
}
But the tr2
won't start , it will start after the ReadKey()
method ,and when I add this first line to Main
method , tr2
starts before ReadKey()
method:
static void Main(string[] args)
{
Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId);
Thread tr2 = new Thread(() =>
{
int a = 0;
Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId);
});
tr2.Start();
Console.ReadKey();
}
Where is the fault ?