我希望每秒都能执行一些代码。我现在使用的代码是:
而Task.Run((Action)ExecuteSomething);
ExecuteSomething()
定义如下: private void ExecuteSomething()
{
Task.Delay(1000).ContinueWith(
t =>
{
//Do something.
ExecuteSomething();
});
}
这个方法会阻塞线程吗?还是我应该在C#中使用Timer
类?而且似乎 Timer 也专门为执行分配了一个单独的线程(?)