tags:

views:

84

answers:

1

Hello... 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.

+2  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

adrift
Thank you very much... you are great
yazanpro
but microsoft is not.... with this constraint...
yazanpro
Sorry but I am very new to this website, I don't know how to mark an answer as the accepted answer...
yazanpro
There should be a green outline of a large checkmark under the vote count for this answer. Simply click the checkmark's outline and this answer will be marked as accepted.
Cameron