继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

线程Thread传参数

侃侃无极
关注TA
已关注
手记 221
粉丝 7
获赞 25

 出自http://hi.baidu.com/ydalbj/blog/item/330b8d13f6959dd5f6039ec4.html

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.");

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP