timer control

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

    #1

    timer control

    hi all,

    i m having some problem in timer control.

    sub timer.tick()
    timer.stop()
    do...something
    timer.enabled = true
    end sub

    this works fine. but after timer.stop() when i try to enable it from some
    other functions it doesnt work. and the timer stops forever

    thnx


  • Jared Parsons [MSFT]

    #2
    Re: timer control

    Hello Ratnesh,
    sub timer.tick()
    timer.stop()
    do...something
    timer.enabled = true
    end sub
    After calling timer.Stop(), you need to call timer.Start() to restart the
    timer.

    --
    Jared Parsons [MSFT]
    jaredpar@online .microsoft.com
    All opinions are my own. All content is provided "AS IS" with no warranties,
    and confers no rights.


    Comment

    • Ratnesh Raval

      #3
      Re: timer control

      thanks jared,

      but that not working either. i've tried both ways, even both together. but
      no luck

      "Jared Parsons [MSFT]" <jaredpar@onlin e.microsoft.com wrote in message
      news:61f143b4c7 e8c86e527271e00 4@msnews.micros oft.com...
      Hello Ratnesh,
      >
      >sub timer.tick()
      >timer.stop()
      >do...somethi ng
      >timer.enable d = true
      >end sub
      >
      After calling timer.Stop(), you need to call timer.Start() to restart the
      timer.
      --
      Jared Parsons [MSFT]
      jaredpar@online .microsoft.com
      All opinions are my own. All content is provided "AS IS" with no
      warranties, and confers no rights.
      >
      >

      Comment

      • Jared Parsons [MSFT]

        #4
        Re: timer control

        Hello Ratnesh,
        thanks jared,
        >
        but that not working either. i've tried both ways, even both together.
        but no luck
        What happens when you call Start( exception, or just nothing). Try toggling
        the Enabled and not calling Stop() at all.

        --
        Jared Parsons [MSFT]
        jaredpar@online .microsoft.com
        All opinions are my own. All content is provided "AS IS" with no warranties,
        and confers no rights.


        Comment

        • Ratnesh Raval

          #5
          Re: timer control


          when i call start or enabled=true. nothing happens in any case. but the tick
          event doesnt fire after the interval.
          i've also tried to toggle the enabled property and didnt use Stop()

          still no luck. i dont know whats wrong.
          its like this

          sub timer.tick()
          timer.stop() [or timer.enabled=f alse]
          do...something
          enabletimersub( )
          end sub
          sub enabletimersub( )
          timer.enabled = true [or timer.start()]
          end sub

          thnx

          "Jared Parsons [MSFT]" <jaredpar@onlin e.microsoft.com wrote in message
          news:61f143b4c9 38c86e57b799510 3@msnews.micros oft.com...
          Hello Ratnesh,
          >
          >thanks jared,
          >>
          >but that not working either. i've tried both ways, even both together.
          >but no luck
          >
          What happens when you call Start( exception, or just nothing). Try
          toggling the Enabled and not calling Stop() at all.
          --
          Jared Parsons [MSFT]
          jaredpar@online .microsoft.com
          All opinions are my own. All content is provided "AS IS" with no
          warranties, and confers no rights.
          >
          >

          Comment

          • Jared Parsons [MSFT]

            #6
            Re: timer control

            Hello Ratnesh,
            when i call start or enabled=true. nothing happens in any case. but
            the tick
            event doesnt fire after the interval.
            i've also tried to toggle the enabled property and didnt use Stop()
            still no luck. i dont know whats wrong.
            its like this
            sub timer.tick()
            timer.stop() [or timer.enabled=f alse]
            do...something
            enabletimersub( )
            end sub
            sub enabletimersub( )
            timer.enabled = true [or timer.start()]
            end sub
            Can you post a code snippet that reproduces the issue?

            --
            Jared Parsons [MSFT]
            jaredpar@online .microsoft.com
            All opinions are my own. All content is provided "AS IS" with no warranties,
            and confers no rights.


            Comment

            • Ratnesh Raval

              #7
              Re: timer control

              its a huge code. but i think i found the reason. herez the deal

              can this be a problem?
              the do..something part runs on another thread which eventually calls the
              enabletimersub( )
              so the main timer.tick() thread and enabletimersub( ) are on different
              threads. is there any solution for this

              sub timer.tick()
              timer.stop() [or timer.enabled=f alse]
              do...something
              end sub
              sub enabletimersub( )
              timer.enabled = true [or timer.start()]
              end sub

              sorry for the delay in telling this point


              "Jared Parsons [MSFT]" <jaredpar@onlin e.microsoft.com wrote in message
              news:61f143b4ce 68c86e5bc88b419 b@msnews.micros oft.com...
              Hello Ratnesh,
              >
              >when i call start or enabled=true. nothing happens in any case. but
              >the tick
              >event doesnt fire after the interval.
              >i've also tried to toggle the enabled property and didnt use Stop()
              >still no luck. i dont know whats wrong.
              >its like this
              >sub timer.tick()
              >timer.stop() [or timer.enabled=f alse]
              >do...somethi ng
              >enabletimersub ()
              >end sub
              >sub enabletimersub( )
              >timer.enable d = true [or timer.start()]
              >end sub
              >
              Can you post a code snippet that reproduces the issue?
              >
              --
              Jared Parsons [MSFT]
              jaredpar@online .microsoft.com
              All opinions are my own. All content is provided "AS IS" with no
              warranties, and confers no rights.
              >
              >

              Comment

              • Ratnesh Raval

                #8
                Re: timer control

                here is the snippet

                Private Sub enabletimersub( )
                MsgBox("hi")
                tmr.Enabled = True
                End Sub
                Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArg s)
                Handles tmr.Tick
                tmr.Stop()
                Dim thread1 As New System.Threadin g.Thread(Addres sOf msgboxfun)
                thread1.Start()
                End Sub


                "Jared Parsons [MSFT]" <jaredpar@onlin e.microsoft.com wrote in message
                news:61f143b4ce 68c86e5bc88b419 b@msnews.micros oft.com...
                Hello Ratnesh,
                >
                >when i call start or enabled=true. nothing happens in any case. but
                >the tick
                >event doesnt fire after the interval.
                >i've also tried to toggle the enabled property and didnt use Stop()
                >still no luck. i dont know whats wrong.
                >its like this
                >sub timer.tick()
                >timer.stop() [or timer.enabled=f alse]
                >do...somethi ng
                >enabletimersub ()
                >end sub
                >sub enabletimersub( )
                >timer.enable d = true [or timer.start()]
                >end sub
                >
                Can you post a code snippet that reproduces the issue?
                >
                --
                Jared Parsons [MSFT]
                jaredpar@online .microsoft.com
                All opinions are my own. All content is provided "AS IS" with no
                warranties, and confers no rights.
                >
                >

                Comment

                • Jared Parsons [MSFT]

                  #9
                  Re: timer control

                  Hello Ratnesh,
                  its a huge code. but i think i found the reason. herez the deal
                  >
                  can this be a problem?
                  the do..something part runs on another thread which eventually calls
                  the
                  enabletimersub( )
                  so the main timer.tick() thread and enabletimersub( ) are on different
                  threads. is there any solution for this
                  That definately could be causing the behavior you are seeing.

                  The solution to this is to use Control.Invoke( ) to set Enabled on the thread
                  the timer lives on.

                  --
                  Jared Parsons [MSFT]
                  jaredpar@online .microsoft.com
                  All opinions are my own. All content is provided "AS IS" with no warranties,
                  and confers no rights.


                  Comment

                  • Ratnesh Raval

                    #10
                    Re: timer control

                    thanks jared,
                    i found that too. but i m not sure how to use it. cna u show me in the
                    snippet or give me any weblink for the help??
                    Private Sub enabletimersub( )
                    MsgBox("hi")
                    tmr.Enabled = True
                    End Sub
                    Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArg s)
                    Handles tmr.Tick
                    tmr.Stop()
                    Dim thread1 As New System.Threadin g.Thread(Addres sOf enabletimersub)
                    thread1.Start()
                    End Sub


                    "Jared Parsons [MSFT]" <jaredpar@onlin e.microsoft.com wrote in message
                    news:61f143b4d3 78c86e663872055 0@msnews.micros oft.com...
                    Hello Ratnesh,
                    >
                    >its a huge code. but i think i found the reason. herez the deal
                    >>
                    >can this be a problem?
                    >the do..something part runs on another thread which eventually calls
                    >the
                    >enabletimersub ()
                    >so the main timer.tick() thread and enabletimersub( ) are on different
                    >threads. is there any solution for this
                    >
                    That definately could be causing the behavior you are seeing.
                    The solution to this is to use Control.Invoke( ) to set Enabled on the
                    thread the timer lives on.
                    --
                    Jared Parsons [MSFT]
                    jaredpar@online .microsoft.com
                    All opinions are my own. All content is provided "AS IS" with no
                    warranties, and confers no rights.
                    >
                    >

                    Comment

                    • Jared Parsons [MSFT]

                      #11
                      Re: timer control

                      Hello Ratnesh,
                      thanks jared,
                      i found that too. but i m not sure how to use it. cna u show me in the
                      snippet or give me any weblink for the help??
                      Private Sub enabletimersub( )
                      MsgBox("hi")
                      tmr.Enabled = True
                      End Sub
                      Private Sub tmr_Tick(ByVal sender As Object, ByVal e As
                      System.EventArg s)
                      Handles tmr.Tick
                      tmr.Stop()
                      Dim thread1 As New System.Threadin g.Thread(Addres sOf
                      enabletimersub)
                      thread1.Start()
                      End Sub
                      Assuming that Me is a Form or Control of some kind, try the following

                      Sub enableTimerSub( )
                      Me.Invoke(CType (AddressOf enableTimerSubI mpl, EventHandler))
                      End Sub

                      Sub enableTimerSubI mpl(ByVal object As Sender, ByVal e As EventArgs)
                      tmr.Enabled = True
                      End Sub

                      Now you shoudl be able to call enableTimerSub( ) from the wrong thread and
                      it will invoke and call enableTimerSubI mpl on the correct thread.

                      --
                      Jared Parsons [MSFT]
                      jaredpar@online .microsoft.com
                      All opinions are my own. All content is provided "AS IS" with no warranties,
                      and confers no rights.


                      Comment

                      • Ratnesh Raval

                        #12
                        Re: timer control

                        thanks again and again
                        it works (finally)
                        phew!!

                        "Jared Parsons [MSFT]" <jaredpar@onlin e.microsoft.com wrote in message
                        news:61f143b4d4 68c86e6a4594859 3@msnews.micros oft.com...
                        Hello Ratnesh,
                        >
                        >thanks jared,
                        >i found that too. but i m not sure how to use it. cna u show me in the
                        >snippet or give me any weblink for the help??
                        >Private Sub enabletimersub( )
                        >MsgBox("hi")
                        >tmr.Enabled = True
                        >End Sub
                        >Private Sub tmr_Tick(ByVal sender As Object, ByVal e As
                        >System.EventAr gs)
                        >Handles tmr.Tick
                        >tmr.Stop()
                        >Dim thread1 As New System.Threadin g.Thread(Addres sOf
                        >enabletimersub )
                        >thread1.Start( )
                        >End Sub
                        >
                        Assuming that Me is a Form or Control of some kind, try the following
                        >
                        Sub enableTimerSub( )
                        Me.Invoke(CType (AddressOf enableTimerSubI mpl, EventHandler))
                        End Sub
                        >
                        Sub enableTimerSubI mpl(ByVal object As Sender, ByVal e As EventArgs)
                        tmr.Enabled = True
                        End Sub
                        >
                        Now you shoudl be able to call enableTimerSub( ) from the wrong thread and
                        it will invoke and call enableTimerSubI mpl on the correct thread.
                        >
                        --
                        Jared Parsons [MSFT]
                        jaredpar@online .microsoft.com
                        All opinions are my own. All content is provided "AS IS" with no
                        warranties, and confers no rights.
                        >
                        >

                        Comment

                        • Ratnesh Raval

                          #13
                          Re: timer control

                          is it possible to do the same thing , If the timer control is in like class
                          module and not on any form.

                          "Jared Parsons [MSFT]" <jaredpar@onlin e.microsoft.com wrote in message
                          news:61f143b4d4 68c86e6a4594859 3@msnews.micros oft.com...
                          Hello Ratnesh,
                          >
                          >thanks jared,
                          >i found that too. but i m not sure how to use it. cna u show me in the
                          >snippet or give me any weblink for the help??
                          >Private Sub enabletimersub( )
                          >MsgBox("hi")
                          >tmr.Enabled = True
                          >End Sub
                          >Private Sub tmr_Tick(ByVal sender As Object, ByVal e As
                          >System.EventAr gs)
                          >Handles tmr.Tick
                          >tmr.Stop()
                          >Dim thread1 As New System.Threadin g.Thread(Addres sOf
                          >enabletimersub )
                          >thread1.Start( )
                          >End Sub
                          >
                          Assuming that Me is a Form or Control of some kind, try the following
                          >
                          Sub enableTimerSub( )
                          Me.Invoke(CType (AddressOf enableTimerSubI mpl, EventHandler))
                          End Sub
                          >
                          Sub enableTimerSubI mpl(ByVal object As Sender, ByVal e As EventArgs)
                          tmr.Enabled = True
                          End Sub
                          >
                          Now you shoudl be able to call enableTimerSub( ) from the wrong thread and
                          it will invoke and call enableTimerSubI mpl on the correct thread.
                          >
                          --
                          Jared Parsons [MSFT]
                          jaredpar@online .microsoft.com
                          All opinions are my own. All content is provided "AS IS" with no
                          warranties, and confers no rights.
                          >
                          >

                          Comment

                          • Jared Parsons [MSFT]

                            #14
                            Re: timer control

                            Hello Ratnesh,
                            is it possible to do the same thing , If the timer control is in like
                            class module and not on any form.
                            You'll need a reference to a control on the foreground thread. Then you
                            can use thatControl.Inv oke() to get onto the correct thread and reset the
                            timer.

                            --
                            Jared Parsons [MSFT]
                            jaredpar@online .microsoft.com
                            All opinions are my own. All content is provided "AS IS" with no warranties,
                            and confers no rights.


                            Comment

                            • Ratnesh Raval

                              #15
                              Re: timer control

                              can you explain how?
                              bcoz the control doesnt seem to have the .invoke() method.

                              i m running timer in the Main module. which calls another class as a
                              saperate thread.

                              thnx

                              "Jared Parsons [MSFT]" <jaredpar@onlin e.microsoft.com wrote in message
                              news:61f143b511 08c86efdf663197 e@msnews.micros oft.com...
                              Hello Ratnesh,
                              >
                              >is it possible to do the same thing , If the timer control is in like
                              >class module and not on any form.
                              >
                              You'll need a reference to a control on the foreground thread. Then you
                              can use thatControl.Inv oke() to get onto the correct thread and reset the
                              timer.
                              --
                              Jared Parsons [MSFT]
                              jaredpar@online .microsoft.com
                              All opinions are my own. All content is provided "AS IS" with no
                              warranties, and confers no rights.
                              >
                              >

                              Comment

                              Working...