C# 5 and async timers

元气小坏坏 提交于 2019-12-04 00:17:48

Try use

await Task.Delay(500);

I have a helper that I really like, just to add a bit of readability:

public static Task Seconds(this int seconds)
{
    return Task.Delay(new TimeSpan(0,0,seconds));
}

This allows me to use something like

await 5.Seconds();

You could easily make similar extension methods for milliseconds, minutes, hours, or whatever.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!