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

ParameterizedThreadStart,ThreadStart的使用,线程Thread传参数

时间:2014-08-26 21:16:46      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   os   使用   ar   art   sp   new   

 

Thread

 

threadWithParam = new Thread(new ParameterizedThreadStart(new ThreadTest().ShowMsg));//threadWithParam.Start("this is a param.");

threadWithParam.Start(

 

thread.Start();

"44444");Thread thread=new Thread(new ThreadStart(new Class11().ShowMsg));

 

表示在 Thread 上执行的方法的委托方法,ThreadStart不能带参数,ParameterizedThreadStart是2.0中新增的,可以带参数(object类型的)

using System.Threading;

public void ShowMsg()
{
    MessageBox.Show("Message Info.");
}

Thread thread = new Thread(new ThreadStart(ShowMsg));
thread.Start();

//带参数

public void ShowMsg(object msg)
{
    MessageBox.Show(msg.ToString());
}

Thread threadWithParam = new Thread(new ParameterizedThreadStart(new ThreadTest().ShowMsg));
threadWithParam.Start("this is a param.");

ParameterizedThreadStart,ThreadStart的使用,线程Thread传参数

标签:style   http   color   os   使用   ar   art   sp   new   

原文地址:http://www.cnblogs.com/lyl6796910/p/3938187.html

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