Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>(transcribed from Ben as comment)</p> <blockquote> <p>just use System.Windows.Forms.Timer. Set the timer for 5 seconds, and handle the Tick event. When the event fires, do the thing.</p> </blockquote> <p>...and disable the timer (IsEnabled=false) before doing your work in oder to suppress a second.</p> <p>The Tick event <em>may</em> be executed on another thread that cannot modify your gui, you can catch this:</p> <pre><code>private System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer(); private void StartAsyncTimedWork() { myTimer.Interval = 5000; myTimer.Tick += new EventHandler(myTimer_Tick); myTimer.Start(); } private void myTimer_Tick(object sender, EventArgs e) { if (this.InvokeRequired) { /* Not on UI thread, reenter there... */ this.BeginInvoke(new EventHandler(myTimer_Tick), sender, e); } else { lock (myTimer) { /* only work when this is no reentry while we are already working */ if (this.myTimer.Enabled) { this.myTimer.Stop(); this.doMyDelayedWork(); this.myTimer.Start(); /* optionally restart for periodic work */ } } } } </code></pre> <hr> <p>Just for completeness: with async/await, one can delay execute something very easy (one shot, never repeat the invocation):</p> <pre><code>private async Task delayedWork() { await Task.Delay(5000); this.doMyDelayedWork(); } //This could be a button click event handler or the like */ private void StartAsyncTimedWork() { Task ignoredAwaitableResult = this.delayedWork(); } </code></pre> <p>For more, see "async and await" in MSDN.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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