class Program
{
public static void Main(String[] args)
{
var c = new C();
var thread = new Thread(new ThreadStart(c.F));
thread.Start();
Console.WriteLine("Exiting main, but the program won't quit yet...");
}
}
class C
{
public void F()
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Waiting {0}", i);
Thread.Sleep(1000);
}
Console.WriteLine("Now the program will quit...");
}
}
控制台应用程序的底层发生了什么导致它在退出之前等待另一个线程完成(指向文档的指针很好)?
注意:我知道这是一个基本问题——我之前总是设法等待线程完成,从未考虑过有一些基础设施为我做这件事......