某大神说de:
能想到用 Task.Delay(delay).ContinueWith(...) 实现的,算是不错。
能想到用 System.Threading.Timer 实现的,我就看他会不能正确使用 Timer 类(这个类实现了IDisposable接口)。
用 Thread.Sleep() 的,可以干掉了。
能写成这样的:
async Task SetTimeout(Action action, TimeSpan delay) {
await Task.Delay(delay);
action();
}
说明是天天玩async/await的,这个人对异步应该很熟悉。