Thread.Sleep replacement in .NET for Windows Store

后端 未结 5 2056
逝去的感伤
逝去的感伤 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:12

    MainPage.xaml.cs

    public MainPage()
    {
      this.InitializeComponent();
      this.WaitForFiveSeconds();
    }
    
    private async void WaitForFiveSeconds()
    {
      await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(5));
      // do something after 5 seconds!
    }
    

提交回复
热议问题