Wait 5 seconds in Universal App
Asked Answered
H

1

7

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?

Haslet answered 28/1, 2016 at 10:29 Comment(1)
You want a timer or simple await Task.Delay(5000); would be sufficient?Moil
G
20

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));
Giraudoux answered 28/1, 2016 at 10:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.