Timer that simply records the duration of a process
-
I need to create a program that can simultaneously turn on up to 4 timers that do not control events, but simply record time down to at least a hundredth of a second. This timer must be visibly updated every hundredth of a second on a form to inform the user of the duration of the processes the program is performing. Is there a way to do this in C#? I looked into the Timer control, but can't figure out how to make it work for this purpose.
-
I need to create a program that can simultaneously turn on up to 4 timers that do not control events, but simply record time down to at least a hundredth of a second. This timer must be visibly updated every hundredth of a second on a form to inform the user of the duration of the processes the program is performing. Is there a way to do this in C#? I looked into the Timer control, but can't figure out how to make it work for this purpose.
Use the
Interval
property of Timer control to set the time interval after which you want to initiate some action. For example:Timer.Interval = 10; //This is 10 millisecond (i.e., one hundredth of a second), as required by you
Then use the
Tick
event of theTimer
control, which will then fire after every time interval set by you as above. In the event-handler ofTick
event, use code to update time in the window as per your requirements. For example, override theOnPaint
method of your window or control where you want to show time and use Graphics methods (Pen
,Brush
, etc.) to show the actual time. Then in afore-mentionedTick
event-handler, simply use a command likethis.Refresh()
to refresh the window which will call theOnPaint
method to draw / show the updated time after every time interval set by you. Regards, Ashok Dhamija _____________________________ Padam Technologies -
I need to create a program that can simultaneously turn on up to 4 timers that do not control events, but simply record time down to at least a hundredth of a second. This timer must be visibly updated every hundredth of a second on a form to inform the user of the duration of the processes the program is performing. Is there a way to do this in C#? I looked into the Timer control, but can't figure out how to make it work for this purpose.
Contrary to what Ashok told you, DON'T use the Timer control. It's resolution is not guaranteed below 15 milliseconds. You have a couple of problems... First, are you going to be able to repaint your data every 10 milliseconds AND monitor your process? Not likely. Repainting is slow... Second, To get the time resolution you want, you really need to use a high resolution timer that is accessed through the QueryPerformanceCounter API. Search the articles for "high resolution timer" and you'll find a bunch of examples and class libraries demonstrating this. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome