秒表问题, [英] Problem in stopwatch,
本文介绍了秒表问题,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我按下按钮时,我会调用计时器"表格:
When I press the button, I call the timer''form:
StopWatch.Show()
'StopWatch.Timer1.Start()
完成后,我将停止计时器:
When I''m finished, I''m stop the timer:
StopWatch.Timer1.Stop()
TextBox6.Text = StopWatch.TextBox1.Text
StopWatch.Close()
问题是,当我通过执行操作启动计时器时,计时器变得比我单独调用计时器表单时要慢.
是什么问题?
The problem is, when I start the timer with doing an operation, the timer become slower than when I call the timer form alone.
What is the problem?
推荐答案
尝试直接使用StopWatch
类.
请参见此处 [
Try using theStopWatch
class directly.
See here[^].
您所说的StopWatch
不是实数"StopWatch
,不是System.Diagnostics.Stopwatch
.我不知道那是什么请参阅我对问题的评论.
为了获得最佳准确性,请使用System.Diagnostics.Stopwatch
.
恐怕您使用System.Windows.Timer
.如果您需要任何合理的精度,请不要使用此类型(基本上,您根本不需要它);这个计时器出了名的不正确!您观察到的可能是其优先级较低的结果.
而且,您几乎不需要使用计时器!在大多数情况下,线程更容易实现.结果将更加健壮;有关详细信息,请参阅我过去的答案:
C#中的计时器线程 [
What you callStopWatch
is not a "real"StopWatch
, notSystem.Diagnostics.Stopwatch
. I don''t know what is it. See my comments to the question.
For best accuracy useSystem.Diagnostics.Stopwatch
.
I''m afraid you useSystem.Windows.Timer
. If you need any reasonable accuracy, don''t use this type (basically, you never need it at all); this timer is notoriously inaccurate! What you observe is maybe the effect of its low priority.
Moreover, you almost never need to use timers! In most cases, a thread is easier to implement; and the result will be much more robust; for details, please see my past answer:
Timer Threading in C#[^].
—SA
这篇关于秒表问题,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文