How to asynchronously wait for x seconds and execute something then?

前端 未结 8 856
深忆病人
深忆病人 2020-12-03 03:03

I know there is Thread.Sleep and System.Windows.Forms.Timer and Monitor.Wait in C# and Windows Forms. I just can\'t seem to be able to figure out how to wait fo

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 03:32

    Have you tried

    public static Task Delay(
        int millisecondsDelay
    )
    

    You can use like this:

    await Task.Delay(5000);
    

    reference: https://msdn.microsoft.com/en-us/library/hh194873(v=vs.110).aspx

提交回复
热议问题