Thread.Sleep replacement in .NET for Windows Store

后端 未结 5 2057
逝去的感伤
逝去的感伤 2020-11-30 21:34

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

For example, this

System.Threading.Thread.Sleep(1000);

5条回答
  •  没有蜡笔的小新
    2020-11-30 22:25

    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.

提交回复
热议问题