码迷,mamicode.com
首页 > 编程语言 > 详细

C# 线程

时间:2015-04-03 19:02:43      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

参考网址: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;

}

C# 线程

标签:

原文地址:http://www.cnblogs.com/xiaocandou/p/4390778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!