내가 이렇게 스레드를 만들려고하고있다 : 그것은 ReadKey()
방법 후 시작됩니다스레드 생성 및 시작
static void Main(string[] args)
{
Thread tr2 = new Thread(() =>
{
int a = 0;
Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId);
});
tr2.Start();
Console.ReadKey();
}
그러나 tr2
이 시작되지 않습니다, 나는 Main
방법이 첫 번째 라인을 추가 할 때, ReadKey()
방법 전에 tr2
시작 :
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();
}
잘못인가?
왜 두 번째 코드에서 주 스레드가 항상 승자입니까? –
이것은 동기화 문제이며 많은 HW/SW 런타임 매개 변수에 따라 달라집니다. 항상 그런 것은 아닙니다 ... 어쨌든 무엇을 묻고 싶습니까? –
OK : stackoverflow.com/a/15144672/328194 –