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. Visual Basic
  4. OnTimedEvent

OnTimedEvent

Scheduled Pinned Locked Moved Visual Basic
tutorial
10 Posts 2 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.
  • C Offline
    C Offline
    ciacia
    wrote on last edited by
    #1

    :doh:HI , I want one function to be called repltedly after a perticular interval. SO i have implemented OnTimedEvent. In that I called my function IsFinish. Isfinish contains some more function calls. If i call Isfinish from a button and get the values after some interval it is workig fine. but if I call this function from OnTimedEvent it is returning null. Please guide. ciacia

    D 2 Replies Last reply
    0
    • C ciacia

      :doh:HI , I want one function to be called repltedly after a perticular interval. SO i have implemented OnTimedEvent. In that I called my function IsFinish. Isfinish contains some more function calls. If i call Isfinish from a button and get the values after some interval it is workig fine. but if I call this function from OnTimedEvent it is returning null. Please guide. ciacia

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      There's no such event in the .NET Framework. Which Timer did you use? There are three in the .NET BCL: System.Threading.Timer System.Timers.Timer System.Windows.Forms.Timer

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      C 1 Reply Last reply
      0
      • D Dave Kreskowiak

        There's no such event in the .NET Framework. Which Timer did you use? There are three in the .NET BCL: System.Threading.Timer System.Timers.Timer System.Windows.Forms.Timer

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        C Offline
        C Offline
        ciacia
        wrote on last edited by
        #3

        i have implemented Imports System.Timers and on form load AddHandler NotifyTimer.Elapsed, AddressOf OnTimedEvent please tell me some other way

        1 Reply Last reply
        0
        • C ciacia

          :doh:HI , I want one function to be called repltedly after a perticular interval. SO i have implemented OnTimedEvent. In that I called my function IsFinish. Isfinish contains some more function calls. If i call Isfinish from a button and get the values after some interval it is workig fine. but if I call this function from OnTimedEvent it is returning null. Please guide. ciacia

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          The System.Timers.Timer uses a seperate thread to call the timer elapsed handler code. If your code is trying to get data from user controls to do it's work, it won't get any data. This is because you can only use a controls methods and properties on the thread that the control was created on. Let's see your OnTimedEvent method...

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          C 1 Reply Last reply
          0
          • D Dave Kreskowiak

            The System.Timers.Timer uses a seperate thread to call the timer elapsed handler code. If your code is trying to get data from user controls to do it's work, it won't get any data. This is because you can only use a controls methods and properties on the thread that the control was created on. Let's see your OnTimedEvent method...

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            C Offline
            C Offline
            ciacia
            wrote on last edited by
            #5

            can you tell me the solution for my problem?

            D 1 Reply Last reply
            0
            • C ciacia

              can you tell me the solution for my problem?

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Please allow me to repeat myself: Let's see your OnTimedEvent method code.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              C 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Please allow me to repeat myself: Let's see your OnTimedEvent method code.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007

                C Offline
                C Offline
                ciacia
                wrote on last edited by
                #7

                Private Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs) IsFinished() End Sub Function IsFinished() As Boolean Dim strLength As String strLength = New String("255") Dim strPosition As String Dim IntLentgh As Integer Dim IntPosition As Integer strPosition = New String("255") mciSendString("status track length", strLength, 255, 0) mciSendString("status track position", strPosition, 255, 0) IntLentgh = CInt(strLength) IntPosition = CInt(strPosition) If IntPosition >= IntLentgh Then notifyTimer.Stop() MsgBox(strPosition) MsgBox(strLength) End If End Function

                D 1 Reply Last reply
                0
                • C ciacia

                  Private Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs) IsFinished() End Sub Function IsFinished() As Boolean Dim strLength As String strLength = New String("255") Dim strPosition As String Dim IntLentgh As Integer Dim IntPosition As Integer strPosition = New String("255") mciSendString("status track length", strLength, 255, 0) mciSendString("status track position", strPosition, 255, 0) IntLentgh = CInt(strLength) IntPosition = CInt(strPosition) If IntPosition >= IntLentgh Then notifyTimer.Stop() MsgBox(strPosition) MsgBox(strLength) End If End Function

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  You're making a mistake with these strings ("255"). You're not creating an empty string 255 characters wide. YOu're making a string 3 characters wide, containging "255". Then in your mciSendString call, you're passing this string in parameters2, but in parameter 3, you're telling mciSendString that the string buffer you just passed in was 255 characters long. No, it's not, it's 3 characters long! I think you're looking for this:

                  Dim strBuffer As New StringBuilder(255)

                  On top of that, you're completely ignoring the return value comming back from the call to mciSendString. You REALLY need to pay attention to that value:

                  Dim rc As Integer
                  rc = mciSendString("status track length", strBuffer, 255, Nothing)
                  If rc > 0 Then
                      ' An error occured!
                  End If
                  

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007

                  C 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    You're making a mistake with these strings ("255"). You're not creating an empty string 255 characters wide. YOu're making a string 3 characters wide, containging "255". Then in your mciSendString call, you're passing this string in parameters2, but in parameter 3, you're telling mciSendString that the string buffer you just passed in was 255 characters long. No, it's not, it's 3 characters long! I think you're looking for this:

                    Dim strBuffer As New StringBuilder(255)

                    On top of that, you're completely ignoring the return value comming back from the call to mciSendString. You REALLY need to pay attention to that value:

                    Dim rc As Integer
                    rc = mciSendString("status track length", strBuffer, 255, Nothing)
                    If rc > 0 Then
                        ' An error occured!
                    End If
                    

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007

                    C Offline
                    C Offline
                    ciacia
                    wrote on last edited by
                    #9

                    OHHH, thaks a lot for your suggestion. I tried stringBuilder but it is not recognizing it I have also imported system.text.stringbuilder .

                    D 1 Reply Last reply
                    0
                    • C ciacia

                      OHHH, thaks a lot for your suggestion. I tried stringBuilder but it is not recognizing it I have also imported system.text.stringbuilder .

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      No, you Import System.Text, not System.Text.StringBuilder.

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                           2006, 2007

                      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