Visual Studio定时器问题
我找不到以下问题的任何解释。希望你能帮助我了解解决方案...
让我们制作一个新的Windows应用程序(使用任何版本的VS),并添加一个按钮,计时器(我们将间隔修改为= 10)和标签(初始文本= “0”)。
在定时器中写入如下代码:
标签1.文本= (Convert.ToInt32(label1.Text) + 1).ToString();
在按钮中写入以下代码:
timer1.Enabled = true;
标签应显示从 0 开始的增量计数器。
从逻辑上讲,每 100 次计数应消耗 1 秒,但这不是事实。 发生的情况是,每 100 次计数消耗略多于 1 秒!!!
此行为的原因是什么???!!!
非常感谢等待您的聆听,并等待您的回复,因为我真的在寻找解释,但我找不到任何东西。
I couldn't find any explanation for the following problem. Hope you to help me to know the solution...
Let's make a new windows appliaction (using any version of VS), and add a button, timer (we modify the interval to become = 10), and a label (with initial text = "0").
write the following code in the timer:
label1.Text =
(Convert.ToInt32(label1.Text) +
1).ToString();
write the following code in the button:
timer1.Enabled = true;
The label should show an incremental counter starting from 0.
Logically, each 100 counts should consume 1 second, but this is NOT the truth.
What happens is that each 100 counts consume a little bit more than 1 second !!!
What is the cause of this behavior????!!!
Thank you very much for your listenning, and waiting for your reply because I really searched for an explenation but I couldn't find anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用
System.Windows.Forms.Timer
,则其精度限制为 55 毫秒。请参阅“备注”部分: System.Windows.Forms.Timer< /a>
If you are using
System.Windows.Forms.Timer
, it is limited to an accuracy of 55 ms.See the Remarks section: System.Windows.Forms.Timer