Windows Phone 8.1 and Windows Runtime Apps How to #7 – Thread.Sleep alternative in Windows Phone 8.1 XAML(Windows Runtime) App

In the earlier version of Windows Phone  , you had the option of using Thread.Sleep which can be used to make a function to wait for specific time . It suspends the current thread for the specified time.

If you targeting Windows Phone Store App (Windows runtime XAML)  , you will need to go via the “asynchronous way”.

The System.Threading.Thread.Sleep method exists for Windows Phone 8.1 Silverlight app template but not for the Windows Runtime XAML App templates.

Thread.Sleep alternative in Windows Phone 8.1 XAML(Windows Runtime) App

Below is a sample code snippet demonstrating the usage of the System.Threading.Tasks.Task.Delay method which creates a task that will complete after the specified time.

 TimeSpan time = TimeSpan.FromSeconds(300);
 await System.Threading.Tasks.Task.Delay(time);

One Response

  1. Елена May 12, 2017 Reply

Leave a Reply