简体   繁体   English

在这种情况下,我应该使用后台工作者或计时器吗?

[英]Should I use background workers or timers in this situation?

I am writing a program that manages a bunch of timers. 我正在编写一个管理大量计时器的程序。

The user has to start them manually, and is able to get information from each timer, to know the remaining time for example. 用户必须手动启动它们,并且能够从每个计时器获取信息,例如以了解剩余时间。

I don't want the GUI to freeze, therefore I don't want to have a timer on the main form thread that freezes the whole thing. 我不想冻结GUI,因此,我不想在冻结整个对象的主窗体线程上使用计时器。

So, does the Timer class send the timer on a new thread, or it keeps it on the main UI thread? 那么,Timer类是在新线程上发送计时器还是将其保留在主UI线程上?

Otherwise, should I use a Background Worker to accomplish this? 否则,我应该使用后台工作人员来完成此任务吗?

The System.Windows.Forms.Timer event runs on the UI thread. System.Windows.Forms.Timer事件在UI线程上运行。

Instead you can use a System.Threading.Timer which runs on a worker thread. 相反,您可以使用在工作线程上运行的System.Threading.Timer

Ref. 参考。 : Comparing the Timer Classes in the .NET Framework Class Library 比较.NET Framework类库中的计时器类

根据您使用的类型计时器,我建议您阅读这些 文章以决定最适合您的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM