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?
Asked
Active
Viewed 516 times
0
-
1Timers are useful here – Sami Kuhmonen Oct 22 '16 at 09:06
1 Answers
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