我有一个方法应该延迟运行指定的时间.
我应该用吗?
Thread thread = new Thread(() => {
Thread.Sleep(millisecond);
action();
});
thread.IsBackground = true;
thread.Start();
Run Code Online (Sandbox Code Playgroud)
要么
Timer timer = new Timer(o => action(), null, millisecond, -1);
Run Code Online (Sandbox Code Playgroud)
我读过一些关于使用的文章Thread.Sleep是糟糕的设计.但我真的不明白为什么.
但是对于使用Timer,Timer有配置方法.由于执行延迟,我不知道如何配置Timer.你有什么建议吗?
或者如果你有延迟执行的替代代码也很感激.