以下代码button2_Click与 button3_Click为button2与button3已绑定事件处理程序,当用户轮流点击button2和button3若干次后,再点击button1时出现系统CPU100%,请问为什么?应如何解决?
private void button2_Click(object sender, EventArgs e)
{
this.button1.Click += new EventHandler(button1_Click);
}
private void button3_Click(object sender, EventArgs e)
{
this.button1.Click -= new EventHandler(button1_Click);
}
private void button1_Click(object sender, EventArgs e)
{
this.Text = DateTime.Now.ToString();
}
2
以下代码button2_Click与 button3_Click为button2与button3已绑定事件处理程序,当用户轮流点击button2和button3若干次后,再点击button1时出现系统CPU100%,请问为什么?应如何解决?
private void button2_Click(object sender, EventArgs e)
{
this.button1.Click += new EventHandler(button1_Click);
}
private void button3_Click(object sender, EventArgs e)
{
this.button1.Click -= new EventHandler(button1_Click);
}
private void button1_Click(object sender, EventArgs e)
{
this.Text = DateTime.Now.ToString();
}
3 个解决方案
#1
点击button2和button3一次后
点击button1将执行以下代码两次
private void button1_Click(object sender, EventArgs e)
{
this.Text = DateTime.Now.ToString();
}
再次点击button2和button3一次后
点击button1将执行以下代码四次
private void button1_Click(object sender, EventArgs e)
{
this.Text = DateTime.Now.ToString();
}
依次类推
点击button1将执行以下代码两次
private void button1_Click(object sender, EventArgs e)
{
this.Text = DateTime.Now.ToString();
}
再次点击button2和button3一次后
点击button1将执行以下代码四次
private void button1_Click(object sender, EventArgs e)
{
this.Text = DateTime.Now.ToString();
}
依次类推
#2
+= 累加.这样的问题,debug下,看下程序执行流程就知道了.
#3
明白了 给分
#1
点击button2和button3一次后
点击button1将执行以下代码两次
private void button1_Click(object sender, EventArgs e)
{
this.Text = DateTime.Now.ToString();
}
再次点击button2和button3一次后
点击button1将执行以下代码四次
private void button1_Click(object sender, EventArgs e)
{
this.Text = DateTime.Now.ToString();
}
依次类推
点击button1将执行以下代码两次
private void button1_Click(object sender, EventArgs e)
{
this.Text = DateTime.Now.ToString();
}
再次点击button2和button3一次后
点击button1将执行以下代码四次
private void button1_Click(object sender, EventArgs e)
{
this.Text = DateTime.Now.ToString();
}
依次类推
#2
+= 累加.这样的问题,debug下,看下程序执行流程就知道了.
#3
明白了 给分