Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Timer that simply records the duration of a process

Timer that simply records the duration of a process

Scheduled Pinned Locked Moved C#
csharptutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thepolishguy
    wrote on last edited by
    #1

    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.

    A D 2 Replies Last reply
    0
    • T thepolishguy

      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.

      A Offline
      A Offline
      Ashok Dhamija
      wrote on last edited by
      #2

      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 the Timer control, which will then fire after every time interval set by you as above. In the event-handler of Tick event, use code to update time in the window as per your requirements. For example, override the OnPaint 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-mentioned Tick event-handler, simply use a command like this.Refresh() to refresh the window which will call the OnPaint method to draw / show the updated time after every time interval set by you. Regards, Ashok Dhamija _____________________________ Padam Technologies

      1 Reply Last reply
      0
      • T thepolishguy

        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.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups