Timer event doesn't get fired

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

    Timer event doesn't get fired

    Hello,

    I'm having a problem with a simple application that I've written. I
    have a form that loads another form. The second form has a timer
    control on it. The timer will not fire for some reason. I have it
    enabled and also used the start method. What might the problem be?

    I've tried System.Windows. Forms.Timers and System.Timers but no luck.

    Any help appreciated

    Mike
  • Jon Skeet [C# MVP]

    #2
    Re: Timer event doesn't get fired

    On Jun 16, 5:59 pm, eljainc <elja...@sbcglo bal.netwrote:
    I'm having a problem with a simple application that I've written. I
    have a form that loads another form. The second form has a timer
    control on it. The timer will not fire for some reason. I have it
    enabled and also used the start method. What might the problem be?
    >
    I've tried System.Windows. Forms.Timers and System.Timers but no luck.
    It's hard to say what's wrong with no code. Could you post a short but
    complete program which demonstrates the problem?

    See http://pobox.com/~skeet/csharp/complete.html for what I mean by
    that.

    Jon

    Comment

    • qglyirnyfgfo@mailinator.com

      #3
      Re: Timer event doesn't get fired

      Is this a windows application? Starts like:

      Application.Run (new Form1());

      or is this a Console application, if its a console application I don't
      think the System.Windows. Forms.Timers will work, I think you will need
      the:

      System.Timers.T imer



      On Jun 16, 11:59 am, eljainc <elja...@sbcglo bal.netwrote:
      Hello,
      >
      I'm having a problem with a simple application that I've written.  I
      have a form that loads another form. The second form has a timer
      control on it. The timer will not fire for some reason. I have it
      enabled and also used the start method.  What might the problem be?
      >
      I've tried System.Windows. Forms.Timers and System.Timers but no luck.
      >
      Any help appreciated
      >
      Mike

      Comment

      • qglyirnyfgfo@mailinator.com

        #4
        Re: Timer event doesn't get fired

        Err... actually never mind.

        but I think you may have problems if you run a timer that inherits
        from Component on a console application or Windows server.... not
        sure... time to do some research!


        On Jun 16, 3:30 pm, qglyirnyf...@ma ilinator.com wrote:
        Is this a windows application? Starts like:
        >
        Application.Run (new Form1());
        >
        or is this a Console application, if its a console application I don't
        think the System.Windows. Forms.Timers will work, I think you will need
        the:
        >
        System.Timers.T imer
        >
        On Jun 16, 11:59 am, eljainc <elja...@sbcglo bal.netwrote:
        >
        >
        >
        Hello,
        >
        I'm having a problem with a simple application that I've written.  I
        have a form that loads another form. The second form has a timer
        control on it. The timer will not fire for some reason. I have it
        enabled and also used the start method.  What might the problem be?
        >
        I've tried System.Windows. Forms.Timers and System.Timers but no luck.
        >
        Any help appreciated
        >
        Mike- Hide quoted text -
        >
        - Show quoted text -

        Comment

        • eljainc

          #5
          Re: Timer event doesn't get fired

          It seems that when I use the command

          Thread.Sleep(xx )

          in my code in the units that use the timers, this is when the problems
          occur. I will need an alternate
          to the Thread.Sleep() method. Is there anything else out there that
          is similar?

          Mike

          Comment

          • Mr. Arnold

            #6
            Re: Timer event doesn't get fired


            "eljainc" <eljainc@sbcglo bal.netwrote in message
            news:351a3de0-cad6-4c87-bf4c-38514f09d310@79 g2000hsk.google groups.com...
            It seems that when I use the command
            >
            Thread.Sleep(xx )
            >
            in my code in the units that use the timers, this is when the problems
            occur. I will need an alternate
            to the Thread.Sleep() method. Is there anything else out there that
            is similar?
            >
            I don't think you fully know how to use a spawned child thread that runs on
            the Thread.Sleep method. I have never ever had a problem with the technology
            with the execution of logic on a child thread on a timed basis.

            Maybe, you should just drag a Timer control out of the Toolbox used for a
            Windows Desktop form solution, place it on the form and use that Timer
            control.




            Comment

            • eljainc

              #7
              Re: Timer event doesn't get fired

              On Jun 16, 4:46 pm, "Mr. Arnold" <MR. Arn...@Arnold.c omwrote:
              "eljainc" <elja...@sbcglo bal.netwrote in message
              >
              news:351a3de0-cad6-4c87-bf4c-38514f09d310@79 g2000hsk.google groups.com...
              >
              It seems that when I use the command
              >
              Thread.Sleep(xx )
              >
              in my code in the units that use the timers, this is when the problems
              occur. I will need an alternate
              to the Thread.Sleep() method. Is there anything else out there that
              is similar?
              >
              I don't think you fully know how to use a spawned child thread that runs on
              the Thread.Sleep method. I have never ever had a problem with the technology
              with the execution of logic on a child thread on a timed basis.
              >
              Maybe, you should just drag a Timer control out of the Toolbox used for a
              Windows Desktop form solution, place it on the form and use that Timer
              control.
              That's what I did. I used a designTime Timer control from the
              toolbox.

              Comment

              • eljainc

                #8
                Re: Timer event doesn't get fired

                On Jun 16, 4:46 pm, "Mr. Arnold" <MR. Arn...@Arnold.c omwrote:
                "eljainc" <elja...@sbcglo bal.netwrote in message
                >
                news:351a3de0-cad6-4c87-bf4c-38514f09d310@79 g2000hsk.google groups.com...
                >
                It seems that when I use the command
                >
                Thread.Sleep(xx )
                >
                in my code in the units that use the timers, this is when the problems
                occur. I will need an alternate
                to the Thread.Sleep() method. Is there anything else out there that
                is similar?
                >
                I don't think you fully know how to use a spawned child thread that runs on
                the Thread.Sleep method. I have never ever had a problem with the technology
                with the execution of logic on a child thread on a timed basis.
                >
                Maybe, you should just drag a Timer control out of the Toolbox used for a
                Windows Desktop form solution, place it on the form and use that Timer
                control.
                The problem that occurs I found is when I mix the timer component with
                the
                System.Diagnost ics.Stopwatch control. I would like to have multiple
                timers
                activated, but some timers I would like to use the .Elapsed property
                of Stopwatch
                so that I know how much time has passed instead of having an event
                fire every xx
                seconds or xx milliseconds.

                Is there a Stopwatch replacement that will not cause conflicts with
                the timer component?

                Thanks
                Mike

                Comment

                • Mr. Arnold

                  #9
                  Re: Timer event doesn't get fired


                  "eljainc" <eljainc@sbcglo bal.netwrote in message
                  news:bee9cb3e-94b0-40ed-a850-fbf915c59fb2@t5 4g2000hsg.googl egroups.com...
                  On Jun 16, 4:46 pm, "Mr. Arnold" <MR. Arn...@Arnold.c omwrote:
                  >"eljainc" <elja...@sbcglo bal.netwrote in message
                  >>
                  >news:351a3de 0-cad6-4c87-bf4c-38514f09d310@79 g2000hsk.google groups.com...
                  >>
                  It seems that when I use the command
                  >>
                  Thread.Sleep(xx )
                  >>
                  in my code in the units that use the timers, this is when the problems
                  occur. I will need an alternate
                  to the Thread.Sleep() method. Is there anything else out there that
                  is similar?
                  >>
                  >I don't think you fully know how to use a spawned child thread that runs
                  >on
                  >the Thread.Sleep method. I have never ever had a problem with the
                  >technology
                  >with the execution of logic on a child thread on a timed basis.
                  >>
                  >Maybe, you should just drag a Timer control out of the Toolbox used for
                  >a
                  >Windows Desktop form solution, place it on the form and use that Timer
                  >control.
                  >
                  The problem that occurs I found is when I mix the timer component with
                  the
                  System.Diagnost ics.Stopwatch control. I would like to have multiple
                  timers
                  activated, but some timers I would like to use the .Elapsed property
                  of Stopwatch
                  so that I know how much time has passed instead of having an event
                  fire every xx
                  seconds or xx milliseconds.
                  >
                  Is there a Stopwatch replacement that will not cause conflicts with
                  the timer component?
                  I don't know. I have never used the Stopwatch. Maybe, you should just use a
                  Timer control in the Toolbox for form controls using the Tick event of the
                  Timer with the Stopwatch. Maybe, that will work for you.

                  Comment

                  • Peter Duniho

                    #10
                    Re: Timer event doesn't get fired

                    On Mon, 16 Jun 2008 16:04:20 -0700, eljainc <eljainc@sbcglo bal.netwrote:
                    [...]
                    Is there a Stopwatch replacement that will not cause conflicts with
                    the timer component?
                    As Jon said, until you post a complete code sample, there's no good way to
                    answer your question.

                    That said: I guarantee you that using the Stopwatch class is not causing
                    your issues. It simply measures passage of time. It doesn't delay
                    threads or cause other problems.

                    What _is_ a problem is calling Thread.Sleep() from a GUI thread, and given
                    that you seem to be using the System.Forms.Ti mer class, you are most
                    likely calling Thread.Sleep() from a GUI thread. If the GUI thread is
                    sleeping, the timer can't fire.

                    Of course, this is all speculation. Since you haven't posted a complete
                    code sample, there's really no way to know what's wrong with your code.

                    Pete

                    Comment

                    Working...