sisquo76
Active member
Is it possible to trigger event whenever seconds on stopwatch change (that means every second, but it has to be synchronized with seconds)?
Thanks,
sisquo76
Thanks,
sisquo76
No, StopWatch doesn't have events, use one of the Timers for this.
If you find the Forms.Timer lacking in precision use the Timers.Timer instead.
Public Function GameTime() As String
Try
Dim iMinutes As Integer = Int(Stopwatch.Elapsed.TotalMinutes)
iMinutes += iAdditionalTime
Dim sMinutes As String = iMinutes.ToString("##0")
Dim sSeconds As String = Stopwatch.Elapsed.Seconds.ToString("00")
Return sMinutes + ":" + sSeconds
Catch
Return "0:00"
End Try
End Function
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim SW As New StreamWriter(ReadFilesPath() + "\Stopwatch.txt", False, System.Text.Encoding.Default)
SW.Write(GameTime)
SW.Close()
End Sub
Absoluty, keep the file open.sisquo76 said:saving this file to network share every 100ms, so I think this is too often.
sisquo76 said:What I would like to do is to find the way to trigger event every time second changes in Stopwatch Class / Is it possible to trigger event whenever seconds on stopwatch change
To write elapsed time each second just store start time (Date.Now) in a variable and trigger Timer 1000ms where you write the timespan (Date.Now-startTime). This is also how the StopWatch class works.JohnH said:No, StopWatch doesn't have events, use one of the Timers for this.