Results 1 to 12 of 12

Thread: Timers

  1. #1

    Thread Starter
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195

    Timers

    So I have an app with a timer in it. In the Timer Tick Event I have some code that draws controls to the screen to the beat of a song.

    I run my app on one machine, it works great.

    I run my app on a different machine, the controls and the beat of the music are way sync.

    Why?

    Isn't the interval on my timer the same no matter what?

    I thought a second was a second???

    Very Confused!

  2. #2
    Hyperactive Member VBD's Avatar
    Join Date
    Apr 2001
    Location
    The Place Above The Place Below Heavin
    Posts
    278

    Timer's are known for being inacurrate

    I haven't heard of it this bad, but it could happen. Look up the get tick count api for accurate measurements of time...
    Hello

  3. #3
    Member
    Join Date
    Mar 2004
    Location
    Middle of nowhere
    Posts
    45
    Wow, we just had a talk about this in class today...

    Apparantly every CPU counts a tick differently, so whenever you switch machines your timer will be running at a different rate... hence the offbeatedness :/

    ---Flac

    p.s. Im aware that i said absolutly nothing of importance, but im bored, so bare with me.
    Everything great once started with the words "That will never catch on, you shouldnt even bother" be great, go against the crowed, do something stupid, you might become famous.

  4. #4
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    so, the project I'm working on won't work.

    I am writing a metronome program that allows the user to customize the speed (duh) and the beat sounds (ticks, clicks, dog barks etc)

    If timing was an absolute must, couldn't you watch the clock on windows and have an event fire every second of the system clock?

    Am I thinking TOO FAR out of the box?

  5. #5
    Hyperactive Member VBD's Avatar
    Join Date
    Apr 2001
    Location
    The Place Above The Place Below Heavin
    Posts
    278

    Actually, that is the idea.

    Back in QBasic, you used Timer to get the seconds since midnight. How about, you use Timer or parse Time$ in .NET. Then use GetTickCount. Find the number of Ticks in a second. Then base your timing off of this. It should be fairly accurate
    Hello

  6. #6

    Thread Starter
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    Well what the hell good are timers if there different on every machine?

    Not very good for my app!


  7. #7
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Have you tried with different timers? I assume you're using the Windows.Forms.Timer which relies on windows messages. The other two timers are System.Timers.Timer and System.Threading.Timer (I think).

    There was a good article comparing timers in msdn mag sometime last year - can search on http://msdn.microsoft.com/msdnmag/

    HTH,
    Mike

  8. #8

    Thread Starter
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    No I haven't tried that, I'll give it a shot when I get to my comp.

  9. #9
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    Originally posted by Hole-In-One
    Well what the hell good are timers if there different on every machine?

    Not very good for my app!

    guess that's why it's still called visual BASIC lol

    I'd say something that needs to be accurate will have to be written
    1) in c++ or another language
    2) for a dedicated machine that doesn't use the logic that Windows uses.

    has anyone tried the other two timers yet?

  10. #10
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi Flac,

    "p.s. Im aware that i said absolutly nothing of importance, but im bored, so bare with me."

    I'm sure we are all ready to BEAR with you, but BARE?? Count me out
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  11. #11
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    FWIW, I've used all three timers in different applications for different purposes. Have not tried for what Hole-In-One is trying to do.

    The Windows.Forms.Timer is the one you usually use for, duh, windows forms. It relies on windows messages, so you can't use it in say, a service application. It is considered the least accurate timer, from what I've read.

    The System.Timers.Timer and the System.Threading.Timer provide almost the same functionality, but the threading timer has a cool option to wait for a specified time before the first tick.

    When I was writing a service application, I used the timers.timer first, but things were a little flaky. Someone suggested using the threading.timer and that seems to have fixed my problem.

    Mike

  12. #12
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    {hmmm.....I wish I was bare right now....}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width