C# 线程
参考网址:http://kb.cnblogs.com/page/149326/
这里要注意当调用有参数方法时,需要在Start 方法中加入参数
public static void ThreadJoin2()
{
IList<Thread> threads = new List<Thread>();
for (int i = 0; i < 3; i++)
{
Thread t = new Thread(new ParameterizedThreadStart(ChildThread2));
threads.Add(t);
}
int c = 0;
foreach (Thread thread in threads)
{
c++;
thread.Start(c);
thread.Join();
}
Console.ReadKey();
}
private static void ChildThread2(object i)
{
for (int j = 0; j < 10; j++)
{
if (j == 0)
{
Console.WriteLine("我是线程{0},完成任务后把工作权还给主线程.", Thread.CurrentThread.Name);
}
else
{
Console.WriteLine("我是线程{0},计数值:{1}", Thread.CurrentThread.Name, j);
}
Thread.Sleep(1000);
}
Thread.CurrentThread.Name = "线程" + i;
}