4
讓我們寫一些簡單的控制檯應用程序(調試模式):如何理解Process.Threads.Count結果?這個變量顯示什麼?
static void Main(string[] args)
{
Process p = Process.GetCurrentProcess();
IList<Thread> threads = new List<Thread>();
Console.WriteLine(p.Threads.Count);
for(int i=0;i<30;i++)
{
Thread t = new Thread(Test);
Console.WriteLine("Before start: {0}", p.Threads.Count);
t.Start();
Console.WriteLine("After start: {0}", p.Threads.Count);
}
Console.WriteLine(Process.GetCurrentProcess().Threads.Count);
Console.ReadKey();
}
static void Test()
{
for(int i=0;i<100;i++)Thread.Sleep(1);
}
你認爲你會在結果中看到?
[Q1]爲什麼p.Threads.Count與Process.GetCurrentProcess()不同。Threads.Count?