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. Timers not working

Timers not working

Scheduled Pinned Locked Moved C#
questionworkspace
10 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.
  • D Offline
    D Offline
    donkaiser
    wrote on last edited by
    #1

    Hello, I have setup a timer to simulate cursor blinking. My program has multiple threads. the thing is that my timer went off but it never calls the function delegate to the Tick events. Do you what is reason? why the tick event nevers calls the function to do my blinking? private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); timer.Tick += new EventHandler(BlinkMode); timer.Interval = 150; timer.Enabled = true; //============================================================= // timer tick handler //============================================================= private void BlinkMode(Object obj, EventArgs ea) { if (!BlinkCursor) { if (curX < 19) // Don't show the cursor if it's at the end of the line { DrawChar('_', curX, curY); // Draw an underscore char at the current coordinate BlinkCursor = true; } } else { DrawChar(HiddenChar, curX, curY); BlinkCursor = false; } } Donkaiser

    M L 3 Replies Last reply
    0
    • D donkaiser

      Hello, I have setup a timer to simulate cursor blinking. My program has multiple threads. the thing is that my timer went off but it never calls the function delegate to the Tick events. Do you what is reason? why the tick event nevers calls the function to do my blinking? private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); timer.Tick += new EventHandler(BlinkMode); timer.Interval = 150; timer.Enabled = true; //============================================================= // timer tick handler //============================================================= private void BlinkMode(Object obj, EventArgs ea) { if (!BlinkCursor) { if (curX < 19) // Don't show the cursor if it's at the end of the line { DrawChar('_', curX, curY); // Draw an underscore char at the current coordinate BlinkCursor = true; } } else { DrawChar(HiddenChar, curX, curY); BlinkCursor = false; } } Donkaiser

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You must start the timer. timer.Start();

      M 1 Reply Last reply
      0
      • D donkaiser

        Hello, I have setup a timer to simulate cursor blinking. My program has multiple threads. the thing is that my timer went off but it never calls the function delegate to the Tick events. Do you what is reason? why the tick event nevers calls the function to do my blinking? private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); timer.Tick += new EventHandler(BlinkMode); timer.Interval = 150; timer.Enabled = true; //============================================================= // timer tick handler //============================================================= private void BlinkMode(Object obj, EventArgs ea) { if (!BlinkCursor) { if (curX < 19) // Don't show the cursor if it's at the end of the line { DrawChar('_', curX, curY); // Draw an underscore char at the current coordinate BlinkCursor = true; } } else { DrawChar(HiddenChar, curX, curY); BlinkCursor = false; } } Donkaiser

        M Offline
        M Offline
        Martin 0
        wrote on last edited by
        #3

        Hello, I think when you are multi threading, you have to use System.Timers.Timer Class. With Timer.Elabsed Event. All the best, Martin

        D 1 Reply Last reply
        0
        • L Lost User

          You must start the timer. timer.Start();

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #4

          timer.Enable starts the timer

          1 Reply Last reply
          0
          • M Martin 0

            Hello, I think when you are multi threading, you have to use System.Timers.Timer Class. With Timer.Elabsed Event. All the best, Martin

            D Offline
            D Offline
            donkaiser
            wrote on last edited by
            #5

            I just want to be more specific about what im doing. Im developping with CF 2.0 VS 2005 and C#. I have a class library which simulate a VT100 like terminal, and i added it as reference to my project. From my main project i call a method from that added class library. In this method, I process all the data that need to be printed on the terminal screen and then i set the timer like the code above which will trigger the BlinkMode method. while debugging, I can see that my timer went off but nothing from the BlinkMode() works. Donkaiser

            M 1 Reply Last reply
            0
            • D donkaiser

              I just want to be more specific about what im doing. Im developping with CF 2.0 VS 2005 and C#. I have a class library which simulate a VT100 like terminal, and i added it as reference to my project. From my main project i call a method from that added class library. In this method, I process all the data that need to be printed on the terminal screen and then i set the timer like the code above which will trigger the BlinkMode method. while debugging, I can see that my timer went off but nothing from the BlinkMode() works. Donkaiser

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #6

              Ok, Then you have an other threading problem. I think you have to invoke the Method which you are calling from your main project. Feel free to ask for a sample code. All the best, Martin

              1 Reply Last reply
              0
              • D donkaiser

                Hello, I have setup a timer to simulate cursor blinking. My program has multiple threads. the thing is that my timer went off but it never calls the function delegate to the Tick events. Do you what is reason? why the tick event nevers calls the function to do my blinking? private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); timer.Tick += new EventHandler(BlinkMode); timer.Interval = 150; timer.Enabled = true; //============================================================= // timer tick handler //============================================================= private void BlinkMode(Object obj, EventArgs ea) { if (!BlinkCursor) { if (curX < 19) // Don't show the cursor if it's at the end of the line { DrawChar('_', curX, curY); // Draw an underscore char at the current coordinate BlinkCursor = true; } } else { DrawChar(HiddenChar, curX, curY); BlinkCursor = false; } } Donkaiser

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Try to put your code in method BlinkMode in try catch. If you get an exception, then you have a problem with the other thread. Use this to avoid exception :

                private void Blinking()
                {
                //... your code is here
                }

                private void BlinkMode(Object obj, EventArgs ea)
                {
                MethodInvoker mi = new MethodInvoker(Blinking);
                Invoke(mi);
                }

                D 1 Reply Last reply
                0
                • L Lost User

                  Try to put your code in method BlinkMode in try catch. If you get an exception, then you have a problem with the other thread. Use this to avoid exception :

                  private void Blinking()
                  {
                  //... your code is here
                  }

                  private void BlinkMode(Object obj, EventArgs ea)
                  {
                  MethodInvoker mi = new MethodInvoker(Blinking);
                  Invoke(mi);
                  }

                  D Offline
                  D Offline
                  donkaiser
                  wrote on last edited by
                  #8

                  well after the timer got fired, BlinkMode() never been called. that why it's weird. I see what you waant me to do but if the BlinkMode() never get called so do the Blinkinh(). Donkaiser

                  M 1 Reply Last reply
                  0
                  • D donkaiser

                    well after the timer got fired, BlinkMode() never been called. that why it's weird. I see what you waant me to do but if the BlinkMode() never get called so do the Blinkinh(). Donkaiser

                    M Offline
                    M Offline
                    Martin 0
                    wrote on last edited by
                    #9

                    public void Blinking() //Is this the Method which is called from your main project? { //Have you tried to invoke this Method? Timer.Tick+=...... } private void BlinkMode(Object obj, EventArgs ea) { // }

                    D 1 Reply Last reply
                    0
                    • M Martin 0

                      public void Blinking() //Is this the Method which is called from your main project? { //Have you tried to invoke this Method? Timer.Tick+=...... } private void BlinkMode(Object obj, EventArgs ea) { // }

                      D Offline
                      D Offline
                      donkaiser
                      wrote on last edited by
                      #10

                      no they are locally called in my terminal. But I guess I solved the problem by setting up the timer inside the constructor. I guess setting up the timer inside a function it's not working. Donkaiser

                      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