Visual Studio定时器问题

发布于 2024-09-26 02:55:47 字数 630 浏览 0 评论 0原文

我找不到以下问题的任何解释。希望你能帮助我了解解决方案...

让我们制作一个新的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹏半生如梦愿梦如真 2024-10-03 02:55:47

如果您使用System.Windows.Forms.Timer,则其精度限制为 55 毫秒。

Windows 窗体计时器组件是单线程的,并且精度限制为 55 毫秒。如果您需要更精确的多线程计时器,请使用 System.Timers 命名空间中的 Timer 类。

请参阅“备注”部分: System.Windows.Forms.Timer< /a>

If you are using System.Windows.Forms.Timer, it is limited to an accuracy of 55 ms.

The Windows Forms Timer component is single-threaded, and is limited to an accuracy of 55 milliseconds. If you require a multithreaded timer with greater accuracy, use the Timer class in the System.Timers namespace.

See the Remarks section: System.Windows.Forms.Timer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文