Which .Net Timer() to use

前端 未结 5 1544
一向
一向 2020-12-09 22:27

I have a legacy WinForms Mdi App in VB.Net 2.0 which I am adding functionality to. One of the additions is a warning which needs to be raised when the current time nears a s

5条回答
  •  眼角桃花
    2020-12-09 23:12

    This article explains pretty well:

    Comparing the Timer Classes in the .NET Framework Class Library

    It sounds like System.Windows.Forms.Timer is the one for you.

    My guideline: If you want the timer to run on your main GUI thread, stick with Windows.Forms.Timer. If it's okay for your timer to be called asynchronously on a thread pool thread, or if you don't want to experience the small delays that System.Windows.Forms.Timer tends to suffer, use System.Timers.Timer. System.Threading.Timer has a different interface from the other two and is not thread-safe; personally, I'm not a fan.

提交回复
热议问题