timer control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    #1

    timer control

    I am working on a emulator and need to have time based events. I've tried
    to use the timer control and discovered that it runs waaaaaaay slow. I set
    the tick frequency to 1, then in the tick event I update a label on my form,
    nothing else. just counting in my head I have determined that it take
    roughly 14 seconds to get through 1000 ticks or 1 second of the timer.

    This really surprises me. I haven't even done any processing yet and the
    thing is already slow. Is this typical of this control?

    If I wanted to have a loop with time based execution, what is the
    appropriate method? This is a windows form app and the emulator is running
    in a dialog.

    Thanks for any suggestions,
    Steve


  • Steven Nagy

    #2
    Re: timer control

    Howdy,

    I would skip the windows API because you are going to get that slowness
    running in a dialog.
    I've noticed that nothing under 20ms in a timer is really accurate
    either.

    Maybe directX would be better for an emulator?

    Otherwise, why not just put your code in a while loop with a sleep
    statement?

    Steven Nagy

    Comment

    • Willy Denoyette [MVP]

      #3
      Re: timer control


      "Steve" <sss@sss.com> wrote in message
      news:u9XpixcAGH A.2256@TK2MSFTN GP11.phx.gbl...[color=blue]
      >I am working on a emulator and need to have time based events. I've tried
      >to use the timer control and discovered that it runs waaaaaaay slow. I set
      >the tick frequency to 1, then in the tick event I update a label on my
      >form, nothing else. just counting in my head I have determined that it
      >take roughly 14 seconds to get through 1000 ticks or 1 second of the timer.
      >
      > This really surprises me. I haven't even done any processing yet and the
      > thing is already slow. Is this typical of this control?
      >
      > If I wanted to have a loop with time based execution, what is the
      > appropriate method? This is a windows form app and the emulator is
      > running in a dialog.
      >
      > Thanks for any suggestions,
      > Steve
      >[/color]

      No, it doesn't run way slow, the timer interval can't be less than the (HW)
      system clock resolution. Some systems have a 10 msec. system clock
      resolution while others may have something like 15 msec. That means that a
      timer will need at least 10 (or 15) seconds to fire 1000 times. Note that I
      said at least, Windows is not a real time OS, so there is no guarantee that
      your timer event handler will be called at the exact time the timer fires,
      the call may get delayed some undefined time depending on the current
      activity of the system
      The same goes for Thread.Sleep(n) , don't expect that Sleep(2) will put the
      thread asleep for 2 msec., no, it will sleep for at least 10 msec.

      Willy.


      Comment

      • Steve

        #4
        Re: timer control


        "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
        news:OpdoS%23lA GHA.140@TK2MSFT NGP12.phx.gbl.. .[color=blue]
        >
        > "Steve" <sss@sss.com> wrote in message
        > news:u9XpixcAGH A.2256@TK2MSFTN GP11.phx.gbl...[color=green]
        >>I am working on a emulator and need to have time based events. I've tried
        >>to use the timer control and discovered that it runs waaaaaaay slow. I
        >>set the tick frequency to 1, then in the tick event I update a label on my
        >>form, nothing else. just counting in my head I have determined that it
        >>take roughly 14 seconds to get through 1000 ticks or 1 second of the
        >>timer.
        >>
        >> This really surprises me. I haven't even done any processing yet and the
        >> thing is already slow. Is this typical of this control?
        >>
        >> If I wanted to have a loop with time based execution, what is the
        >> appropriate method? This is a windows form app and the emulator is
        >> running in a dialog.
        >>
        >> Thanks for any suggestions,
        >> Steve
        >>[/color]
        >
        > No, it doesn't run way slow, the timer interval can't be less than the
        > (HW) system clock resolution. Some systems have a 10 msec. system clock
        > resolution while others may have something like 15 msec. That means that a
        > timer will need at least 10 (or 15) seconds to fire 1000 times. Note that
        > I said at least, Windows is not a real time OS, so there is no guarantee
        > that your timer event handler will be called at the exact time the timer
        > fires, the call may get delayed some undefined time depending on the
        > current activity of the system
        > The same goes for Thread.Sleep(n) , don't expect that Sleep(2) will put the
        > thread asleep for 2 msec., no, it will sleep for at least 10 msec.
        >
        > Willy.
        >
        >[/color]

        Willy, this makes perfect sense, thanks for the thorough explanation. It
        does leave me still with a question, if I don't want to use DirectX like
        Steven suggested, how do I implement a time controlled loop?

        If the system time has a 10ms resolution (or 15 or whatever), then I can't
        count on using that to determine elapsed time. I've never had to do this
        before... If yo uhave any suggestions, I would really appreciate them.

        Thanks again,
        Steve


        Comment

        • Steve

          #5
          Re: timer control


          "Steven Nagy" <learndotnet@ho tmail.com> wrote in message
          news:1134689112 .246491.254080@ o13g2000cwo.goo glegroups.com.. .[color=blue]
          > Howdy,
          >
          > I would skip the windows API because you are going to get that slowness
          > running in a dialog.
          > I've noticed that nothing under 20ms in a timer is really accurate
          > either.
          >
          > Maybe directX would be better for an emulator?
          >
          > Otherwise, why not just put your code in a while loop with a sleep
          > statement?
          >
          > Steven Nagy
          >[/color]

          Hi,

          Thanks for the suggestion. DirectX would be over kill for this and I also
          need to use WinForms for the UI. The sleep statement was interesting, but
          then I read Willys post where he says it suffers from the same time
          resolution as the timer control.

          Thanks again,
          Steve


          Comment

          • Willy Denoyette [MVP]

            #6
            Re: timer control


            "Steve" <sss@sss.com> wrote in message
            news:emZfsImAGH A.3456@TK2MSFTN GP11.phx.gbl...[color=blue]
            >
            > "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
            > news:OpdoS%23lA GHA.140@TK2MSFT NGP12.phx.gbl.. .[color=green]
            >>
            >> "Steve" <sss@sss.com> wrote in message
            >> news:u9XpixcAGH A.2256@TK2MSFTN GP11.phx.gbl...[color=darkred]
            >>>I am working on a emulator and need to have time based events. I've
            >>>tried to use the timer control and discovered that it runs waaaaaaay
            >>>slow. I set the tick frequency to 1, then in the tick event I update a
            >>>label on my form, nothing else. just counting in my head I have
            >>>determined that it take roughly 14 seconds to get through 1000 ticks or 1
            >>>second of the timer.
            >>>
            >>> This really surprises me. I haven't even done any processing yet and
            >>> the thing is already slow. Is this typical of this control?
            >>>
            >>> If I wanted to have a loop with time based execution, what is the
            >>> appropriate method? This is a windows form app and the emulator is
            >>> running in a dialog.
            >>>
            >>> Thanks for any suggestions,
            >>> Steve
            >>>[/color]
            >>
            >> No, it doesn't run way slow, the timer interval can't be less than the
            >> (HW) system clock resolution. Some systems have a 10 msec. system clock
            >> resolution while others may have something like 15 msec. That means that
            >> a timer will need at least 10 (or 15) seconds to fire 1000 times. Note
            >> that I said at least, Windows is not a real time OS, so there is no
            >> guarantee that your timer event handler will be called at the exact time
            >> the timer fires, the call may get delayed some undefined time depending
            >> on the current activity of the system
            >> The same goes for Thread.Sleep(n) , don't expect that Sleep(2) will put
            >> the thread asleep for 2 msec., no, it will sleep for at least 10 msec.
            >>
            >> Willy.
            >>
            >>[/color]
            >
            > Willy, this makes perfect sense, thanks for the thorough explanation. It
            > does leave me still with a question, if I don't want to use DirectX like
            > Steven suggested, how do I implement a time controlled loop?
            >
            > If the system time has a 10ms resolution (or 15 or whatever), then I can't
            > count on using that to determine elapsed time. I've never had to do this
            > before... If yo uhave any suggestions, I would really appreciate them.
            >
            > Thanks again,
            > Steve
            >[/color]

            Steve,
            If you need to fire a timer at an interval that is smaller than say 20 msec.
            you are stuck, even DirectX can't help you with that. Could you please
            explain what exactly you want to achieve.

            Willy.





            Comment

            • Steve

              #7
              Re: timer control


              "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
              news:ewiRSemAGH A.3584@TK2MSFTN GP14.phx.gbl...[color=blue]
              >
              > "Steve" <sss@sss.com> wrote in message
              > news:emZfsImAGH A.3456@TK2MSFTN GP11.phx.gbl...[color=green]
              >>
              >> "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
              >> news:OpdoS%23lA GHA.140@TK2MSFT NGP12.phx.gbl.. .[color=darkred]
              >>>
              >>> "Steve" <sss@sss.com> wrote in message
              >>> news:u9XpixcAGH A.2256@TK2MSFTN GP11.phx.gbl...
              >>>>I am working on a emulator and need to have time based events. I've
              >>>>tried to use the timer control and discovered that it runs waaaaaaay
              >>>>slow. I set the tick frequency to 1, then in the tick event I update a
              >>>>label on my form, nothing else. just counting in my head I have
              >>>>determine d that it take roughly 14 seconds to get through 1000 ticks or
              >>>>1 second of the timer.
              >>>>
              >>>> This really surprises me. I haven't even done any processing yet and
              >>>> the thing is already slow. Is this typical of this control?
              >>>>
              >>>> If I wanted to have a loop with time based execution, what is the
              >>>> appropriate method? This is a windows form app and the emulator is
              >>>> running in a dialog.
              >>>>
              >>>> Thanks for any suggestions,
              >>>> Steve
              >>>>
              >>>
              >>> No, it doesn't run way slow, the timer interval can't be less than the
              >>> (HW) system clock resolution. Some systems have a 10 msec. system clock
              >>> resolution while others may have something like 15 msec. That means that
              >>> a timer will need at least 10 (or 15) seconds to fire 1000 times. Note
              >>> that I said at least, Windows is not a real time OS, so there is no
              >>> guarantee that your timer event handler will be called at the exact time
              >>> the timer fires, the call may get delayed some undefined time depending
              >>> on the current activity of the system
              >>> The same goes for Thread.Sleep(n) , don't expect that Sleep(2) will put
              >>> the thread asleep for 2 msec., no, it will sleep for at least 10 msec.
              >>>
              >>> Willy.
              >>>
              >>>[/color]
              >>
              >> Willy, this makes perfect sense, thanks for the thorough explanation. It
              >> does leave me still with a question, if I don't want to use DirectX like
              >> Steven suggested, how do I implement a time controlled loop?
              >>
              >> If the system time has a 10ms resolution (or 15 or whatever), then I
              >> can't count on using that to determine elapsed time. I've never had to
              >> do this before... If yo uhave any suggestions, I would really appreciate
              >> them.
              >>
              >> Thanks again,
              >> Steve
              >>[/color]
              >
              > Steve,
              > If you need to fire a timer at an interval that is smaller than say 20
              > msec. you are stuck, even DirectX can't help you with that. Could you
              > please explain what exactly you want to achieve.
              >
              > Willy.[/color]


              I'm trying to make a very basic emulator for an embedded device. In
              emulating the UI, there are different durations at which things happen.
              When I designed the application in my head and on paper, processing tasks
              evey millisecond was the cleanest way. I can make it work good enough with
              100 ms intervals, I will just have some slight inaccuracies, this is just a
              UI emulator, so it's not critical.


              Comment

              Working...