stop watch using vb.net 2005

how can i create a stop watch using vb.net 2005
i am performing a data extraction job using windows forms and want to display time elapsed on the form. how can i do it

Thanks


Answer this question

stop watch using vb.net 2005

  • Fab IT

    Are you sure you have the Enabled property and the Interval properties of the timer set

    Set a breakpoint on the tick event to see if you reach the tick event at all.

  • JanBaan

    I tried your code and it worked fine. Of course I don't know how you declare stopWatch, tmrMain and what CreateReport does; so I just created standard components and commented out CreateReport.

    It is strange that you did not hit a break point in tmrMain_Tick. Did you try putting a breakpoint on If stopWatch.IsRunning Then

    Without more code I'm afraid I cannot investigate further.

    Regards,



  • jswilson

    Yes, Enabled property is set to True and Interval property is set to 50. I placed a breakpoint on the tick event and surprisingly it doesn't break into the event Tongue Tied

    wht cud be the prob!



  • BaNgInG

    Dear Lot
      i suggest to use a Timer control from the toolbox and display it on a label to
      the user
     

  • sp_412000

    Using Application.DoEvents doesn't help.


  • yennisse

    Using Stopwatch class i am displaying the elapsed time in a label on the form. The problem is that time elapsed time is not getting updated in the label. It shows the elapsed time as soon as i click the button to start processing data and doesn't update elapsed time there after. below is the code




    Private Sub btnCreateReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateReport.Click

          stopWatch.Start()
          Call CreateReport()

    End Sub

    Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick

          If stopWatch.IsRunning Then

             Dim ts As TimeSpan = stopWatch.Elapsed

             lblTimer.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", _
                                  ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)

          End If

    End Sub


     



    Thanks



  • Ram Marappan

    Hi,

    Would you try adding this into btnCreateReport_Click It looks like you forgot to start the timer.
       tmrMain.Start()

    Hope this helps,

  • M. Buragohain

    If you post the code we may try to help you out.

    Marinus

  • Hayder Marzouk

    you need to force a message to update the screen contents. Add the following after the lblTimer.text line

    Application.DoEvents()

    Cathal

  • CodeNet

    You can use the Stopwatch class. This class has members like Start, Stop, Reset.



  • FreakFrossard

    i am starting the timer as it's Enabled property is set to True on form load.



  • Jamskin Chen

    Using Stopwatch class i am displaying the elapsed time in a label on the form. The problem is that time elapsed time is not getting updated in the label. It shows the elapsed time as soon as i click the button to start processing data and doesn't update elapsed time there after. below is the code




    Private Sub btnCreateReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateReport.Click
          stopWatch.Start()
          Call CreateReport()
    End Sub

    Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick
          If stopWatch.IsRunning Then
             Dim ts As TimeSpan = stopWatch.Elapsed
             lblTimer.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", _
                                  ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
          End If
    End Sub


     



  • Aaron Steers

    Can some1 pls help me with this.

    Thanks

  • reZer

    Using Stopwatch class i am displaying the elapsed time in a label on the form. The problem is that time elapsed time is not getting updated in the label. It shows the elapsed time as soon as i click the button to start processing data and doesn't update elapsed time there after. below is the code



    Private Sub btnCreateReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateReport.Click

          stopWatch.Start()

          Call CreateReport()

    End Sub

    Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick

          If stopWatch.IsRunning Then

             
    Dim ts As TimeSpan = stopWatch.Elapsed

             lblTimer.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", _
                                  ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)

          
    End If

    End Sub


     



    Thanks



  • stop watch using vb.net 2005