System.Timers.Timer/Threading.Timer vs Thread with WhileLoop + Thread.Sleep For Periodic Tasks

前端 未结 4 1151
悲&欢浪女
悲&欢浪女 2020-12-02 11:23

In my application I have to send periodic heartbeats to a \"brother\" application.

Is this better accomplished with System.Timers.Timer/Threading.Timer or Using a Th

4条回答
  •  一生所求
    2020-12-02 11:41

    System.Threading.Timer has my vote.

    System.Timers.Timer is meant for use in server-based (your code is running as a server/service on a host machine rather than being run by a user) timer functionality.

    A Thread with a While loop and Thread.Sleep command is truly a bad idea given the existance of more robust Timer mecahnisms in .NET.

提交回复
热议问题