Results 1 to 6 of 6

Thread: Timer fireing off twice in a row when it should not

  1. #1

    Thread Starter
    Addicted Member Porsche944's Avatar
    Join Date
    Apr 2005
    Location
    Ann Arbor
    Posts
    182

    Angry Timer fireing off twice in a row when it should not

    I am doing a little work with a timer in my program to control a thread. The only code I have in the timer is in the tick event which has the line

    Console.WriteLine = "Test"

    I set the timers interval to 10 seconds in the desgin view. When I start my timer I get two Tests in the console window really fast then 10 seconds go by and another two Test but, I only have one test in the tick event.

    I set a break at the timer tick event and when the event is fire it ads a line to the console then refires it self yet there is not code that is doing this.

    What am I doing wrong?

  2. #2
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: Timer fireing off twice in a row when it should not

    A timer's interval uses milliseconds, not seconds. For example, if you wanted 1 second, you would have to put in 1000. For 10 seconds, 10000.

  3. #3

    Thread Starter
    Addicted Member Porsche944's Avatar
    Join Date
    Apr 2005
    Location
    Ann Arbor
    Posts
    182

    Re: Timer fireing off twice in a row when it should not

    yea i know it's miliseconds I have the timer set to 10,000

  4. #4
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: Timer fireing off twice in a row when it should not

    Move your code to the timers elapse event not the tick event.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  5. #5
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Timer fireing off twice in a row when it should not

    Elaspe and tick are events from 2 different timers
    System.Timers.Timer uses elapse
    Windows.Forms.Timer uses tick

    porsche can you post the code in the tick event?
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  6. #6
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Timer fireing off twice in a row when it should not

    Check to make sure you are not adding the handler twice to handle the event. Check the windows generated code section.

    The most common cause of this is you have an "add handler" in the generated code and a "handles Timer1.Tick" after the function.

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