Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait 5 seconds in Universal App

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?

like image 520
lostluke Avatar asked Jan 28 '16 10:01

lostluke


1 Answers

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));
like image 132
croxy Avatar answered Sep 21 '22 02:09

croxy