Thread.Sleep replacement in .NET for Windows Store

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

    I just had the same problem and found another interesting solution that I wanted to share with you. If you really want to block the thread I would do it like this (thanks @Brannon for the "slim" hint):

    // `waitHandle.Set` is never called, so we wait always until the timeout occurs
    using (var waitHandle = new ManualResetEventSlim(initialState: false))
    {
        waitHandle.Wait(TimeSpan.FromSeconds(5));
    }
    

提交回复
热议问题