我将创建这样的线程:
static void Main(string[] args)
{
Thread tr2 = new Thread(() =>
{
int a = 0;
Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId);
});
tr2.Start();
Console.ReadKey();
}
但是tr2
不会开始,它将在ReadKey()
方法之后开始,当我将第一行添加到Main
方法时,在方法tr2
之前开始ReadKey()
:
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();
}
错在哪里?