倒数计时器,以毫秒或秒为单位. [英] Countdown Timer in milliseconds or seconds.

查看:64
本文介绍了倒数计时器,以毫秒或秒为单位.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在.net Framework 4上使用Visual Basic 2010,并且即时消息发布,创建了一个简单的倒计时计时器.我想知道是否有人使用计时器控件和间隔以毫秒或秒为单位创建了新的simplist方法以创建倒数计时器.

我目前有一个带有1个文本框和1个计时器控件的表单.我希望文本框从300000(5分钟)的间隔开始显示以毫秒为单位的倒计时.

任何帮助或指导都会有所帮助.

干杯Tom

Hi All,

I am using visual basic 2010 on .net framework 4 and im have an issuing creating a simple count down timer. i was wondering if anyone new the simplist method to create a countdown timer in milliseconds or seconds using a timer control and intervals.

I currently have a form with 1 textbox and 1 timer control. i want the textbox display a countdown in milliseconds from interval of 300000 (5mins).

Any help or direction would be helpful.

Cheers Tom

推荐答案

我同意John关于线程与计时器的评估.
另请参阅我过去的答案:
C#中的计时器线程 [ http://msdn.microsoft.com/en-us/library/system.threading. timer.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.timers. timer.aspx [ ^ ].

但是,您不能通过计时器的回调委托或事件处理程序在UI上调用任何内容.相反,您需要调用System.Windows.Threading.DispatcherInvokeBeginInvoke方法(都是Forms或WPF)或System.Windows.Forms.Control(仅限Forms).

有关调用和代码示例的详细说明,请参见我过去的回答:
Control.Invoke()与Control.BeginInvoke() [ ^ ],
Treeview Scanner和MD5的问题 [
I agree with John about his evaluation of thread vs timer.
See also my past answer:
Timer Threading in C#[^]

If you really need a timer, any of the other types of Timer:
System.Threading.Timer or System.Timers.Timer, see:
http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx[^],
http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx[^].

However, you cannot call anything on UI from the timer''s callback delegate or event handler. Instead, you need to call the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (both Forms or WPF) or System.Windows.Forms.Control (Forms only).

For detailed explanations of the invocation and code samples, please see my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

—SA


不要使用Winforms Timer控件.使用System.Timers.Timer代替.当然,如果是我,我会使用线程和委托而不是ANY Timer对象,因为

0)您拥有更多控制权

1)Windows Timer甚至是Windows中优先级最低的消息,在繁忙的系统中,也不保证可以由OS处理.线程是更好的选择.
Don''t use the Winforms Timer control. Use System.Timers.Timer instead. Of course, if it were me, I''d use a thread and a delegate instead of ANY Timer object because

0) You have more control

1) The Windows Timer even is the lowest priority message in Windows and on a busy system, it''s NOT guaranteed to be processed by the OS. A thread is a better choice.


这篇关于倒数计时器,以毫秒或秒为单位.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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