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

Timer

Scheduled Pinned Locked Moved C#
questioncsharp
6 Posts 4 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.
  • R Offline
    R Offline
    rahultaing
    wrote on last edited by
    #1

    Can anyone tell me how do I count the number of seconds elapsed after a certain piece of C# code is executed?

    C R C V 4 Replies Last reply
    0
    • R rahultaing

      Can anyone tell me how do I count the number of seconds elapsed after a certain piece of C# code is executed?

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      I would create something to hold a start time. And then when I need to know the number of elapsed seconds I'd get the current time and calculate the difference.


      "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

      R 1 Reply Last reply
      0
      • C Colin Angus Mackay

        I would create something to hold a start time. And then when I need to know the number of elapsed seconds I'd get the current time and calculate the difference.


        "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

        R Offline
        R Offline
        rahultaing
        wrote on last edited by
        #3

        What do i need to write to get the start time and stop time?

        1 Reply Last reply
        0
        • R rahultaing

          Can anyone tell me how do I count the number of seconds elapsed after a certain piece of C# code is executed?

          R Offline
          R Offline
          rahultaing
          wrote on last edited by
          #4

          what do i need to write to get the start time and stop time?

          1 Reply Last reply
          0
          • R rahultaing

            Can anyone tell me how do I count the number of seconds elapsed after a certain piece of C# code is executed?

            C Offline
            C Offline
            Corinna John
            wrote on last edited by
            #5

            DateTime - DateTime = TimeSpan ;) DateTime start = DateTime.Now; DoSomething(); TimeSpan result = DateTime.Now - start; Console.WriteLine(result.Seconds); _________________________________ Please inform me about my English mistakes, as I'm still trying to learn your language!

            1 Reply Last reply
            0
            • R rahultaing

              Can anyone tell me how do I count the number of seconds elapsed after a certain piece of C# code is executed?

              V Offline
              V Offline
              V 0
              wrote on last edited by
              #6

              You can also use the Timer class. Set it to one second and count the number of times the ElapsedTimeEvent is called. I think however the DateTime methid would be better. ;) Coulda, woulda, shoulda doesn't matter if you don't.

              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