用控制檯測試多個線程

class Program
{
static void Main(string[] args)
{
ThreadStart num = new ThreadStart(PrintNum);
Thread ConstrolNum = new Thread(num);pwa

ThreadStart str = new ThreadStart(PrintStr);
Thread ConstrolStr = new Thread(str);string

Stopwatch watch = new Stopwatch();
watch.Start();
ConstrolNum.Start();
ConstrolStr.Start();it

while (true)
{
if (ConstrolNum.ThreadState == System.Threading.ThreadState.Stopped && ConstrolStr.ThreadState == System.Threading.ThreadState.Stopped)
{
watch.Stop();
Console.WriteLine(watch.Elapsed.TotalMilliseconds);
break;
}
}class

Console.ReadKey();sed

}static

private static void PrintNum()
{
for (int i = 1; i < 1000; i++)
{
Console.WriteLine(i);
}
}top

private static void PrintStr()
{
for (int i = 1; i < 1000; i++)
{
Console.WriteLine("當前數爲:{0}", i);
}
}
}di

相關文章
相關標籤/搜索