0

I want to add a 2 second delay for a program I am making in c# and I do not want to totally lock up the main thread because I want a progress bar to still move and then 2 seconds later, I want the whole program to exit. How will I do this?

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
sniff122
  • 5
  • 5

1 Answers1

2

You can use Task.Delay with an async event handler:

public async void SomeEventhandler(object obj, EventArgs e)
{
    await Task.Delay(2000);
    // Do stuff after delay.
}
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321