如何从不同的线程/类启用计时器

编程入门 行业动态 更新时间:2024-10-28 21:22:12
本文介绍了如何从不同的线程/类启用计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原帖:如何访问来自 C# 中另一个类的计时器

我什么都试过了.

-事件

-无法完成调用,因为计时器没有 InvokeRequired 属性.

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

-公共/内部财产

没有任何效果,代码正在执行,timer.Enabled 属性被设置为true",但它不打勾.如果我调用事件或只是在非表单类中更改属性 -静态方法 - 它确实有效.

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/en-us/library/system.windows.forms.timer.aspx

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

更多推荐

[db:关键词]

本文发布于:2023-03-28 18:13:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/736933.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计时器   线程

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!