ToolCollection/ToolCollection/ClassStopwatch.vb

37 lines
1.3 KiB
VB.net

Public Class ClassStopwatch
Public label As String
Public stopwatch As Stopwatch
Public Sub New(label As String)
Me.label = label
stopwatch = New Stopwatch()
stopwatch.Start()
End Sub
Public Function Done() As String
Try
stopwatch.Stop()
Dim ts As TimeSpan = stopwatch.Elapsed
Dim timespan_ = String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
If ts.Minutes > 0 Then
timespan_ = String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
ElseIf ts.Seconds > 0 And (ts.Minutes > 0) = False Then
timespan_ = String.Format("{0:00}.{1:00} seconds", ts.Seconds, ts.Milliseconds / 10)
ElseIf (ts.Seconds > 0) = False And ts.Milliseconds > 0 Then
timespan_ = String.Format("{0:00}.{1:00} seconds", ts.Seconds, ts.Milliseconds / 10)
End If
If timespan_ <> "00:00.00" Then
Dim message = String.Format("{0} || {1}", label, timespan_)
Return message
Else
Return ""
End If
Catch ex As Exception
Return "ERROR: " & ex.Message
End Try
End Function
End Class