Threading.Timer与Forms.Timer [英] Threading.Timer vs. Forms.Timer

查看:76
本文介绍了Threading.Timer与Forms.Timer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题的简短形式:什么时候在多线程WinForms应用程序中使用Forms.Timer是合适的?

The short form of this question: When, if ever, is it appropriate to use the Forms.Timer in a multithreaded WinForms application?

更具体地说,我正在设计一个应用程序,该应用程序使用多个System.Threading.Timers异步启动进程,检查包含那些异步进程结果的队列,并更新统计信息以由应用程序的主窗体显示.

More specifically, I am architecting an application that uses multiple System.Threading.Timers to launch processes asynchronously, check queues containing the results of those asynchronous processes, and update the statistics to be shown by the application's main form.

在这样的应用程序中,是否适合使用Forms.Timer来实际检查应用程序统计信息并将其绘制到主窗体中,还是仅仅需要用扳手来确保应用程序的平稳运行?

In an application like that, is it appropriate to use a Forms.Timer to actually check the application statistics and draw them to the main form or would that just throw a wrench into the application's smooth running?

推荐答案

Forms.Timer注册计时器以在计时器关闭时发送消息.引发的事件被视为GUI事件. System.Threading.Timer使用线程阻塞方法.基本上,应该将Forms.Timer用于面向GUI的计时器(向用户界面添加一些效果),并使用Threading.Timer安排任务和其他事情.

Forms.Timer registers the timer to send a message when the timer goes off. The event raised is treated like a GUI event. System.Threading.Timer uses a thread blocking approach. Basically, you should use Forms.Timer for your GUI oriented timers (to add some effects to the user interface) and Threading.Timer for scheduling tasks and other things.

这篇关于Threading.Timer与Forms.Timer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆