Thread.Sleep() in a Portable Class Library

前端 未结 5 2028
长发绾君心
长发绾君心 2021-02-18 15:05

The MSDN docs say Thread.Sleep() can be used in a portable class library. The compiler says otherwise. What are my alternatives besides a spin-loo

5条回答
  •  你的背包
    2021-02-18 15:37

    System.Threading.Tasks.Task.Delay(ms).Wait();
    

    works as a drop-in replacement for

    System.Threading.Thread.Sleep(ms);
    

    This works fine when porting a legacy code base.

提交回复
热议问题