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. Problem with timer event fireing

Problem with timer event fireing

Scheduled Pinned Locked Moved C#
helpcomquestion
8 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
    Tom Wright
    wrote on last edited by
    #1

    I have a socket app. I have an event that is fired when the connection is closed. This event is caught stops my other two timers, and enables a 3rd timer, sets the timer interval and starts it. But it never happens, it never drops in to the tick event method. I have two other timers that are started from an event...like when the connection is up, they work fine. But it does not work when the connection is closed. Not sure what code to post to help out as the event is in once class, the socket in another class, etc. Why would a timer not fire on the tick event? Thanks

    Tom Wright tawright915@gmail.com

    M S 2 Replies Last reply
    0
    • T Tom Wright

      I have a socket app. I have an event that is fired when the connection is closed. This event is caught stops my other two timers, and enables a 3rd timer, sets the timer interval and starts it. But it never happens, it never drops in to the tick event method. I have two other timers that are started from an event...like when the connection is up, they work fine. But it does not work when the connection is closed. Not sure what code to post to help out as the event is in once class, the socket in another class, etc. Why would a timer not fire on the tick event? Thanks

      Tom Wright tawright915@gmail.com

      M Offline
      M Offline
      mikone
      wrote on last edited by
      #2

      you should try to get more information. do you use an ide? if yes, which one and does it support breakpoints?! if so, use them. make sure you see the line, where the timer is started, being executed. also print out the values of the timer before it get started. compare the code of the other two timers and so on. before starting any timer, you should print its values to make sure its set up correctly. try to debug it because, as you already said, noone will know where to start searching.

      T 2 Replies Last reply
      0
      • M mikone

        you should try to get more information. do you use an ide? if yes, which one and does it support breakpoints?! if so, use them. make sure you see the line, where the timer is started, being executed. also print out the values of the timer before it get started. compare the code of the other two timers and so on. before starting any timer, you should print its values to make sure its set up correctly. try to debug it because, as you already said, noone will know where to start searching.

        T Offline
        T Offline
        Tom Wright
        wrote on last edited by
        #3

        yes I'm stepping thru my code (VS2003) and the interval is getting set. The timer is getting started. It's just never fired. The last statement that is stepped thru is: this.autoEvent.Set(); this is in the socket class. It is reseting my events when the socket is closed. Then control is back at the interface...waiting for the timer to fire.

        Tom Wright tawright915@gmail.com

        1 Reply Last reply
        0
        • M mikone

          you should try to get more information. do you use an ide? if yes, which one and does it support breakpoints?! if so, use them. make sure you see the line, where the timer is started, being executed. also print out the values of the timer before it get started. compare the code of the other two timers and so on. before starting any timer, you should print its values to make sure its set up correctly. try to debug it because, as you already said, noone will know where to start searching.

          T Offline
          T Offline
          Tom Wright
          wrote on last edited by
          #4

          Question: can I make my timers avaliable in other classes...so that when the connection is closed, that class can start the timer, instead of me having to fire an event? thanks

          Tom Wright tawright915@gmail.com

          M 1 Reply Last reply
          0
          • T Tom Wright

            Question: can I make my timers avaliable in other classes...so that when the connection is closed, that class can start the timer, instead of me having to fire an event? thanks

            Tom Wright tawright915@gmail.com

            M Offline
            M Offline
            mikone
            wrote on last edited by
            #5

            Sure you can, depending on how you've designed your classes :) If you want to make this timer available in other classes you have to have an instance of the class where the timer is in and provide a public interface (e.g. a property) for the other classes. Also check if your events are bound correctly and let them being fired by some function which definitely works (100%), to make sure that its a problem related with the timer or other code. You should try to fire the event at least once, to make sure that the timer itself works...

            1 Reply Last reply
            0
            • T Tom Wright

              I have a socket app. I have an event that is fired when the connection is closed. This event is caught stops my other two timers, and enables a 3rd timer, sets the timer interval and starts it. But it never happens, it never drops in to the tick event method. I have two other timers that are started from an event...like when the connection is up, they work fine. But it does not work when the connection is closed. Not sure what code to post to help out as the event is in once class, the socket in another class, etc. Why would a timer not fire on the tick event? Thanks

              Tom Wright tawright915@gmail.com

              S Offline
              S Offline
              sjembek
              wrote on last edited by
              #6

              Are you using the System.Windows.Forms.Timer or the System.Threading.Timer? If you're using the tick event it looks like you're using the windows forms timer. If so, make sure you're using it in a class that inherits from Form, otherwise it won't work. The Threading.Timer is a better option in that case, you can set the interval and a callback function in its constructor.

              T 1 Reply Last reply
              0
              • S sjembek

                Are you using the System.Windows.Forms.Timer or the System.Threading.Timer? If you're using the tick event it looks like you're using the windows forms timer. If so, make sure you're using it in a class that inherits from Form, otherwise it won't work. The Threading.Timer is a better option in that case, you can set the interval and a callback function in its constructor.

                T Offline
                T Offline
                Tom Wright
                wrote on last edited by
                #7

                It's a forms timer. The timers are setup in my form class. My other timers are working fine.. They start and stop okay.....and they too are being started when the connection event is fired. Then the close event is fired I stop the first two timers and start a thrid timer. This will allow the connection to restart after a certain elasped time. However this third timer is never started. Even though I'm enabling, setting the time interval, and calling the start method. Thanks

                Tom Wright tawright915@gmail.com

                S 1 Reply Last reply
                0
                • T Tom Wright

                  It's a forms timer. The timers are setup in my form class. My other timers are working fine.. They start and stop okay.....and they too are being started when the connection event is fired. Then the close event is fired I stop the first two timers and start a thrid timer. This will allow the connection to restart after a certain elasped time. However this third timer is never started. Even though I'm enabling, setting the time interval, and calling the start method. Thanks

                  Tom Wright tawright915@gmail.com

                  S Offline
                  S Offline
                  sjembek
                  wrote on last edited by
                  #8

                  If you're stopping another timer, why not just change its interval to the interval you had in mind for the third timer and hook up the right event listener to it?

                  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