Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
System.Timers.Timer 的 Elapsed 事件是否与 System.Windows.Forms.Timer 的 Tick 事件有效相同?
在特定情况下,使用其中一个而不是另一个有优势吗?
其他答案提供了很多细节,但是您提到的两个计时器之间的主要区别在于,System.Windows.Forms.Timer它将在 UI 线程上调用回调,而System.Timers.Timer将使用核心线程池中的一个线程。
System.Windows.Forms.Timer
System.Timers.Timer
检查这些链接here和here以完整了解.Net框架中的计时器。
定时器分为三种。
我个人更喜欢System.Timers.Timer它是线程安全的。