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
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.
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
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)
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
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
stop watch using vb.net 2005
rpgoldberg
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,
CSI
i suggest to use a Timer control from the toolbox and display it on a label to
the user
aaaaNNNN
Set a breakpoint on the tick event to see if you reach the tick event at all.
David Crocker
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
wht cud be the prob!
Sergey Kononov
Marinus
areia
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.ClickstopWatch.Start()
Call CreateReport()End
SubPrivate
Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick If stopWatch.IsRunning ThenDim 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
ckris
Herman Post
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
W S Jones
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
Troika
Application.DoEvents()
Cathal
Jason Barrett
quodlibet
Thanks
dean183
i am starting the timer as it's Enabled property is set to True on form load.
ldcooke
Would you try adding this into btnCreateReport_Click It looks like you forgot to start the timer.
tmrMain.Start()
Hope this helps,