如何使来自不同的线程/类定时器 [英] How to enable a timer from a different thread/class

查看:91
本文介绍了如何使来自不同的线程/类定时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原帖: HTTP:/ /stackoverflow.com/questions/725413/how-to-access-a-timer-from-another-class-in-c

Original post: http://stackoverflow.com/questions/725413/how-to-access-a-timer-from-another-class-in-c

我什么都试过了。

- 活动

-Invoke不能做,因为定时器不有InvokeRequired属性

-Invoke can't be done,because Timers don't have InvokeRequired property.

- 公共/内部属性

-Public/internal property

毫无效果,正在执行的代码,定时器.Enabled属性被设置为true,但它并不Tick.If我所说的事件或只是改变从窗体类的属性在非静态方法 - 它蜱和作品

Nothing worked,the code is being executed,the timer.Enabled property is being set to "true" ,but it doesn't Tick.If I call the event or just change the property from the form class in a NON-static method - it does tick and works.

我从来不知道它会带我一天可能更获取如何使用一个体面的定时器。

I never knew it would take me a day and probably more to acquire how to use a decent timer.

如果没有办法要做到这一点,有什么事我可以使用效果类同定时器(延迟,启用/禁用)?

If there's no way to do this,is there anything else I can use that works similiar to the timer(delay,enable/disable)?

推荐答案

您应该使用从System.Timers命名空间中的Timer类,而不是WinForms的Timer控件,如果你想多线程支持。检查的WinForms Timer控件的MSDN文档的详细信息:

You should use the Timer class from the System.Timers namespace, and not the WinForms Timer control, if you want multi-threading support. Check the MSDN documentation for the WinForms Timer control for more information:

http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx

这篇关于如何使来自不同的线程/类定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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