首页 > 编程语言 > 详细

C# 线程

时间:2015-04-03 19:01:47      阅读:338      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!