yazanpro
yazanpro

Reputation: 4752

Visual Studio timer problem

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.

Upvotes: 0

Views: 780

Answers (1)

Jeff Ogata
Jeff Ogata

Reputation: 57783

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

Upvotes: 2

Related Questions