Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's one idea that's just fallen out of my head. I don't know how workable it is and can't see an obvious way to make it more generic, but it might be a start. All it does is provide a buffer for button click events (substitute with your event as necessary).</p> <pre><code>class ButtonClickBuffer { public event EventHandler BufferedClick; public ButtonClickBuffer(Button button, int queueSize) { this.queueSize= queueSize; button.Click += this.button_Click; } private int queueSize; private List&lt;EventArgs&gt; queuedEvents = new List&lt;EventArgs&gt;(); private void button_Click(object sender, EventArgs e) { queuedEvents.Add(e); if (queuedEvents.Count &gt;= queueSize) { if (this.BufferedClick!= null) { foreach (var args in this.queuedEvents) { this.BufferedClick(sender, args); } queuedEvents.Clear(); } } } } </code></pre> <p>So your subscriber, instead of subscribing as:</p> <pre><code>this.button1.Click += this.button1_Click; </code></pre> <p>Would use a buffer, specifying how many events to wait for:</p> <pre><code>ButtonClickBuffer buffer = new ButtonClickBuffer(this.button1, 5); buffer.BufferedClick += this.button1_Click; </code></pre> <p>It works in a simple test form I knocked up, but it's far from production-ready!</p> <p>You said you didn't want to wait for an event to see if there is a queue waiting, which is exactly what this does. You could substitute the logic inside the buffer to spawn a new thread which monitors the queue and dispatches events as necessary. God knows what threading and locking issues might arise from that!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload