System.Threading.Timer

vik*_*ram 7 c# multithreading timer

当我们使用System.Threading.Timer时,那么在创建计时器的线程上执行的方法是什么?或者是在另一个线程中执行?

class Timer
{
    static void Main()
    {
        TimerCallback tcall = statusChecker.CheckStatus;
        Timer stateTimer = new Timer(tcb, autoEvent, 1000, 250);
    }
}
class StatusChecker
{
    public void CheckStatus(Object stateInfo)
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,如果timer delegate(CheckStatus)调用的方法是在主线程中执行还是在另一个线程中执行?

Øyv*_*hen 6

System.Threading.Timer 将在线程池中的另一个线程上执行其工作.

System.Windows.Forms.Timer 将在现有(GUI)线程上执行.