【发布时间】:2022-01-06 10:38:37
【问题描述】:
我想每秒执行一些代码。我现在使用的代码是:
Task.Run((Action)ExecuteSomething);
而ExecuteSomething()定义如下:
private void ExecuteSomething()
{
Task.Delay(1000).ContinueWith(
t =>
{
//Do something.
ExecuteSomething();
});
}
这个方法会阻塞线程吗?还是应该在 C# 中使用 Timer 类?而且好像Timer also dedicates a separate thread for execution (?)
【问题讨论】:
-
关于“单独线程”,所有定时器之间只有一个线程共享。
标签: c# multithreading asynchronous timer task