Groups | Blog | Home
all groups > dotnet performance > october 2003 >

dotnet performance : Performance overhead with Timer


cnu
10/20/2003 1:51:14 AM
Hi,
Both System.Windows.Forms.Timer and System.Timers.Timer
seem to be having performance overhead if the appl. runs
for longer periods with the timer. Is there any other way
Michael Giagnocavo [MVP]
10/20/2003 11:04:48 AM
While I think you should look into the cause of the timer problem and try to
resolve it (what framework are you using?) you can do something similar by
having a loop:

public static void DoTimerStuff() {
bed:
Console.WriteLine(DateTime.Now);
System.Threading.Thread.Sleep(5000);
goto bed;
}

(Ok, replace the label and goto with a while(true). It compiles into the
same stuff anyways but I thought goto bed was cute.)

And starting a new thread to run that loop. If the precise time is needed
(suppose you want it to run every 5 minutes, and the process takes 1 minute
to run), then you'll need to store another DateTime, and do a sleep based on
the difference between the target DateTime and the current time.

-mike
MVP

[quoted text, click to view]



shawnr NO[at]SPAM online.microsoft.com (
10/30/2003 9:39:59 PM
What version of the Framework are you using? Are you saying that the
longer an app runs, the more overhead you see from the timer? Can you give
a code example of how you are using your timer?

--
This posting is provided "AS IS" with no warranties, and confers no rights.

Thanks
Shawn Rothlisberger
CLR Performance Test
AddThis Social Bookmark Button