本文介绍了当button1仍在工作时,如何按第二个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void button1_Click(object sender,EventArgs e)
{
for(int i = 0; i< 1000000; i ++)
{
label1.Text = i.ToString();
}
}
private void button2_Click(object sender,EventArgs e)
{
label1.Text = 0.ToString() ;
}< / pre
按下按钮1后,我正在增加,按钮2被锁定,直到我完成。
我怎么能随时按下button2?
我尝试过:
< pre> private void button1_Click(object sender,EventArgs e)
{
Thread th1 = new Thread(Increment);
th1.Start();
}
private void Increment()
{
for(int i = 0; i< 10000; i ++)
{
label1.Text = i.ToString();
}
}
private void button2_Click(object sender,EventArgs e)
{
reset();
}
private void reset()
{
label1.Text = 0.ToString();
}
解决方案
private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < 1000000; i++) { label1.Text = i.ToString(); } } private void button2_Click(object sender, EventArgs e) { label1.Text = 0.ToString(); }</pre After i press button1, i is increasing and button2 is Locked until i is finished. how can i press button2 at anytime? What I have tried: <pre> private void button1_Click(object sender, EventArgs e) { Thread th1 = new Thread(Increment); th1.Start(); } private void Increment() { for (int i = 0; i < 10000; i++) { label1.Text = i.ToString(); } } private void button2_Click(object sender, EventArgs e) { reset(); } private void reset() { label1.Text = 0.ToString(); }
解决方案
这篇关于当button1仍在工作时,如何按第二个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!