-1

I have a button click event that should perform if statements every 2 seconds, one by one. Without the timer, each of the K statements gets implemented instantly on click.

I've tried Thread.Sleep(), but it freezes the instance and then does everything without pausing.

Thank you in advance!

Lance U. Matthews
  • 14,475
  • 6
  • 41
  • 65
Arso
  • 1
  • 2
    Please tag the question with the UI framework and version of .NET (Core|Framework) you are using. I removed the VB.NET and Visual Studio tags as those are not relevant here. It'd also be very helpful to show what that `Click` event handler looks like now so someone doesn't have to guess when they attempt to rewrite it. – Lance U. Matthews May 06 '22 at 22:41
  • If there are only a certain number of `if` statements it might be simpler to just `await Task.Delay(2000);` between them all – Caius Jard May 07 '22 at 04:57
  • Not sure I'd pick any of those in that duplicate for your situation. The accepted is closest but it would perhaps be hard for you to apply and doesn't use headache-reducing `await`. However, I'm not prepared to go up against multiple people deciding your question is a duplicate of it, even if I could do. I'll confine the advice to comments; the other approach you could consider, which is fairly easy to do is to increment a counter every time a timer ticks and then have `Timer_Tick(...){ counter++; if(counter == 1) DoThis(); if(counter == 2) DoThat();` and have the timer on 2 seconds – Caius Jard May 07 '22 at 05:02

0 Answers0