计时器在线程C#中不起作用 [英] Timer don't work in thread C#

查看:138
本文介绍了计时器在线程C#中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我不能在线程中使用计时器(timer.Tick事件).

我该如何使用?
感谢

Hi every body, I can''t use timer (timer.Tick event) in a thread.

How can I use this ?
thanks

推荐答案

您的问题措辞很差. 不工作"没有告诉我们任何事情.而且也缺少对情况的描述.

这是什么样的计时器?
您是如何初始化的?
您是通过调用Start()或将Enabled设置为true来启动它的吗?

:)
Your question is very poorly phrased. "Dont''t work" does not tell us anything. And a description of the circumstances are absent too.

What kind of timer is this?
How did you initialize it?
Did you start it by calling Start(), or by setting Enabled true?

:)


如果您使用的是System.Windows.Forms.Timer,则应仅在主线程上对其进行触摸,因此请使用Visual Designer或在主线程上运行的代码进行创建主线程,并仅在主线程上调用其方法和属性;因此不要尝试通过说SerialPort.DataReceived处理程序来启动/停止它.

并且,请学习正确地提出问题,并提供所有必要的信息.

:)
If what you are using is a System.Windows.Forms.Timer then you should touch it only on the main thread, so create it with Visual Designer or with code running on the main thread, and call its methods and properties on the main thread only; so don''t try and start/stop it from say a SerialPort.DataReceived handler.

And please learn to ask a question properly, providing all necessary information.

:)


我同时使用了这两种方法,但这不起作用.
我在互联网上用google搜索,发现计时器无法在线程中启动,这是真的吗?
I use the both method but this not work.
I google in internet i found out that timer can not be started in a thread is it true?


这篇关于计时器在线程C#中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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