c#按钮点击排队 [英] c# button click queueing
问题描述
我有一个按钮单击事件处理程序,其中有一个开关案例,它控制一个事件处理程序中的多个按钮。
I have a button click event handler with a switch case in it that controls multiple buttons in one event handler.
我需要使用队列,因为当单击一个按钮并进行一些处理时,第二次按钮单击不会影响第一次按钮单击,但添加到队列。我不想使用 .enabled = false;
,因为它会完全丢弃第二次点击,我目前正在编辑某人的软件,所以我不会想要打破我不知道的事情,那么你建议什么呢?
I need to use a queue because while one button is clicked and doing some processing, second button click won't interfere with the first button click, but added to the queue. I don't want to use .enabled=false;
because it'll discard the second click completely, and I'm currently editing someone's software at work so I don't want to break things that I don't know, so what are you suggesting?
推荐答案
=http://msdn.microsoft.com/tr-tr/library/system.collections.queue.aspx =nofollow> System.Collections.Queue
I did succeed this with System.Collections.Queue
代码是:
private Queue<Button> Button_Queue = new Queue<Button>();
private bool isProcessing = false;
private void Button_Click((object sender, EventArgs e){
if(isProcessing){
Button_Queue.Enqueue(this);
}
else
{
isProcessing = true;
// code here
isProcessing = false;
while(Button_Queue.Count > 0){
Button_Queue.Dequeue().PerformClick();
}
}
当然我和这里有点不同,因为我需要传递一些变量,我的点击方法为此修改。
of course mine is slightly different from this because I need to pass some variables and my click method is modified for this.
这篇关于c#按钮点击排队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!