I need to make a pause in a Windows 10 UWP App.
And the only thing i want is to wait 5 seconds to do the next action. I tried Task. Sleep but then the pressed button was frozen...
Pause should be here:
loading.IsActive = true;
//int period = 5000;
//ThreadPoolTimer PeriodicTimer =
//ThreadPoolTimer.CreatePeriodicTimer(TimeSpan.FromMilliseconds(period));
loading.IsActive = false;
How can I make a 5s pause?
You could use the Task.Delay()
method:
loading.IsActive = true;
await Task.Delay(5000);
loading.IsActive = false;
When using this method your UI doesn't freeze.
Edit
A more readable way IMO would be to don't pass the milliseconds as parameter like in the above example. But instead pass a TimeSpan
instance:
await Task.Delay(TimeSpan.FromSeconds(5));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With