Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.NET Timer Problems

Status
Not open for further replies.

benlogan1981

Programmer
Dec 9, 2001
14
GB
Why can I not get my .net c# program to execute a function every MS. Using the timers here...
Why if I run a timer over 20 seconds and try to increment a counter every millisecond does the timer end up at about 1300 instead of about 20,000 ?? I can't my head round this at all. The MSDN demo available from that link is quite interesting.

It prints a statement at every 'tick', yet with the timer set to an interval of 1ms it prints out roughly 45 lines every second, instead of around 1000.

I am missing something really obvious here - this is causing me a real headache.

Any help would be much appreciated.

 
I believe that the Timer is not re-entrant.

Imagine what would happen if the Timer fired every millisecond and you had database access in the handler that took 5 minutes to run!

[vampire][bat]
 
I am not sure I follow. If you have a play with the MSDN demo app you will see that for an interval of 1ms the events are raised far less than every 1/1000th of a second. That is what I dont understand; in other words how do I get my application to perform a simple operation every millisecond. I appreciate the above comment regarding lengthy executions during a small interval, but I am not concerned with doing anything other than incrementing a counter at the minute.

Any further help would be much appreciated. earthandfire - could I ask simply how you would go about performing a very simple task every 1MS?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top