用线程怎样调用带参数的方法?
一直报错:“coco”的重载均与委托“System.Threading.ThreadStart”不匹配privatevoidbutton1_Click(objectsen...
一直报错:“coco”的重载均与委托“System.Threading.ThreadStart”不匹配
private void button1_Click(object sender, EventArgs e)
{
tCount = new Thread(new ThreadStart(coco));
tCount.Start(1000000000);//调用带参方法
}
void coco(int count)
{
double per = 0;
for (int i = 0; i < count; i++)
{
per = (double)i*100 / count;
progressBar1.Value = (int)per;//显示进度
}
} 展开
private void button1_Click(object sender, EventArgs e)
{
tCount = new Thread(new ThreadStart(coco));
tCount.Start(1000000000);//调用带参方法
}
void coco(int count)
{
double per = 0;
for (int i = 0; i < count; i++)
{
per = (double)i*100 / count;
progressBar1.Value = (int)per;//显示进度
}
} 展开
1个回答
展开全部
定义一个全局变量啦。。
int count=0;
private void button1_Click(object sender, EventArgs e)
{
tCount = new Thread(new ThreadStart(coco));
count = 1000000000;
tCount.Start();//调用带参方法
}
void coco()
{
double per = 0;
for (int i = 0; i < count; i++)
{
per = (double)i*100 / count;
progressBar1.Value = (int)per;//显示进度
}
int count=0;
private void button1_Click(object sender, EventArgs e)
{
tCount = new Thread(new ThreadStart(coco));
count = 1000000000;
tCount.Start();//调用带参方法
}
void coco()
{
double per = 0;
for (int i = 0; i < count; i++)
{
per = (double)i*100 / count;
progressBar1.Value = (int)per;//显示进度
}
参考资料: 全局变量
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询