Wait 5 seconds in the universal application

I need to pause the Windows 10 UWP application.

And the only thing I want is to wait 5 seconds to do the next action. I tried the task. Sleep, but then the pressed button was frozen ...

The pause should be here:

loading.IsActive = true;

   //int period = 5000;
   //ThreadPoolTimer PeriodicTimer =
   //ThreadPoolTimer.CreatePeriodicTimer(TimeSpan.FromMilliseconds(period));

loading.IsActive = false;

How to pause 5 seconds?

+4
source share
1 answer

You can use the method Task.Delay():

loading.IsActive = true;
await Task.Delay(5000);
loading.IsActive = false;

When using this method, your user interface does not freeze.

Edit
In a more readable way, IMO would not pass milliseconds as a parameter, as in the example above. But instead pass the instance TimeSpan:

await Task.Delay(TimeSpan.FromSeconds(5));
+15

Source: https://habr.com/ru/post/1626328/


All Articles