-1

Is it possible to execute a method after 30 second from background on click event(no regular event)? By "from background" I mean that UI is still working; there's no active waiting. I can't use System.Threading.Thread.Sleep(x) and so on.

I tried Timer Class, but I can't get it working how I want.

Servy
  • 202,030
  • 26
  • 332
  • 449
user3463614
  • 95
  • 1
  • 11

1 Answers1

4

You can make the button click event handler async, and then just delay the task for the time you need:

private async void YourButton_Click(object sender, EventArgs e)
{
    await Task.Delay(2000);

    // do whatever you want
}
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325