Showing posts with label Windows Store apps. Show all posts
Showing posts with label Windows Store apps. Show all posts

Friday, January 18, 2013

Thread.Sleep replacement in .NET for Windows Store

Thread.Sleep doesn't seem to be supported in .NET for Windows Store apps.

For example, this
            System.Threading.Thread.Sleep(1000);

Windows Store apps embrace asynchrony - and an "asynchronous pause" is provided by Task.Delay. So within an asynchronous method, you'd write:
await Task.Delay(TimeSpan.FromSeconds(30));
... or whatever delay you want. The asynchronous method will continue 30 seconds later, but the thread will not be blocked, just as for all await expressions.