请教关于多线程的问题
这程序我照书上打的,书上说这程序输出结果应该是2个线程的结果交替的显示出来,可为什么我这显示的结果总是先是main线程的结果,然后才是worker线程的结果?
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace _CSharp_Console
{
class Program
{
static void ShowNumbers()
{
Thread thisThread = Thread.CurrentThread;
Console.WriteLine( "Starting Thread: " + thisThread.Name);
int n = 10000000;
for (int i = 1; i < 8 * n; i++)
{
if (i % n == 0)
Console.WriteLine(thisThread.Name + ":count has reached " + i);
}
}
static void Main(string[] args)
{
Thread thisThread = Thread.CurrentThread;
thisThread.Name = "Main ";
Thread worker = new Thread(delegate()
{
ShowNumbers();
Console.WriteLine( "Worker Thread Finished ");
});
worker.Name = "Worker ";
ShowNumbers(); //主线程调用ShowNumbers函数
worker.Start(); //worker线程调用ShowNumbers函数
Console.WriteLine( "Main Thread Finished ");