C#中如何让线程执行带有参数的函数

Crystal_PLUS 2006-05-22 09:22:28
在C#中,如何让线程执行带有参数的函数?
...全文
266 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tl0 2006-05-23
  • 打赏
  • 举报
回复
//以下代码将演示怎么让一个线程入口可以具有参数
private void button1_Click(object sender, System.EventArgs e)
{
for ( int i = 0; i < this.listView1.Items.Count; i++)
{
ThreadMethod method = new ThreadMethod( this.listView1.Items[i].Text );
System.Threading.Thread t = new System.Threading.Thread(
new System.Threading.ThreadStart( method.ThreadRun) );
t.Start();
}
}
public class ThreadMethod
{
private string _param = string.Empty;
public ThreadMethod(string param )
{
this._param = param;
}
public void ThreadRun()
{
MessageBox.Show( _param );
}
}
marvelstack 2006-05-23
  • 打赏
  • 举报
回复
http://blog.csdn.net/zhzuo/archive/2004/06/10/22037.aspx
woyaomoney 2006-05-22
  • 打赏
  • 举报
回复
invoke
Firestone2003 2006-05-22
  • 打赏
  • 举报
回复
全局变量
zhangfire 2006-05-22
  • 打赏
  • 举报
回复
使用构造函数
全局或环境变量
数据库
真相重于对错 2006-05-22
  • 打赏
  • 举报
回复
ms-help://MS.MSDNQTR.2003FEB.2052/cpsamples/html/thread_pools_technology_sample.htm
泡沫游走 2006-05-22
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=200185

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧