确保您的按钮禁用或您所做的任何其他锁定是您在事件处理程序中所做的 /first/ 事情。如果您甚至可以在第一条指令触发之前将两个点击事件排队,我会感到非常惊讶,但我想如果您使用的是一台非常慢且被其他应用程序困住的计算机,这是可能的。
在这种情况下,请使用标志。
private bool runningExclusiveProcess = false;
public void onClickHandler(object sender, EventArgs e)
{
if (!runningExclusiveProcess)
{
runningExclusiveProcess = true;
myButton.Enabled = false;
// Do super secret stuff here
// If your task is synchronous, then undo your flag here:
runningExclusiveProcess = false;
myButton.Enabled = true;
}
}
// Otherwise, if your task is asynchronous with a callback, then undo your flag here:
public void taskCompletedCallback()
{
runningExclusiveProcess = false;
myButton.Enabled = true;
}
如果您仍然可以通过两次点击来完成类似的操作,那么请确保您没有意外订阅了 doubleClick 事件,或者发生了其他任何奇怪的事情。