C#多线程JOIN方法初探
[说明:刚接触多线程时,弄不明白Join()的
试一试:线程的插入
//注意添加命名空间
using System.Threading;
static void Main(string[] args)
{
//线程A
Thread ThreadA = new Thread(delegate()
{
for (int i = 0; i <= 100000000; i++)
{
if (i % 1000000 == 0)
{
Console.Write('A');
}
}
});
//线程B
Thread ThreadB = new Thread(delegate()
{
for (int i = 0; i <= 50000000; i++)
{
if (i % 1000000 == 0)
{
Console.Write('B');
}
}
//在这里插入线程A
ThreadA.Join();
for (int i = 0; i <= 50000000; i++)
{
if (i % 1000000 == 0)
{
Console.Write('b');
}
}
});
//启动线程
ThreadA.Start();
ThreadB.Start();
}
由运行结果可以看出,一开始两个线程交替
http://www.cnblogs.com/millen/archive/2009/09/07/1520353.html