### Determine App Running Time

An example to determine the running (execution) time for code blocks.
The library jDateUtils is used.
Code
Dim timestart As Long = DateTime.Now
Log("Time Start = " & DateTime.Time(timestart))
Log("Block A running...")
Delay(5000)
Log("Duration Block A (s) = " & TimeDiffSec(DateTime.Time(timestart), DateTime.Time(DateTime.now)))
Output
Time Start = 11:53:04
Block A running...
Duration Block A (s) = 5
'Returns time difference in seconds for timeformat HH:mm:ss
'Example:
'Dim timestart As Long = DateTime.Now
'Do something like a delay for 5 seconds
'Log("Duration (s) = " & TimeDiffSec(DateTime.Time(timestart), DateTime.Time(DateTime.now)))
`Sub TimeDiffSec(starttime As String, endtime As String) As Int
Dim result As String
DateTime.TimeFormat="HH:mm:ss"
Dim st As Long = DateTime.TimeParse(starttime)
Dim et As Long = DateTime.TimeParse(endtime)
Dim td As Period = DateUtils.PeriodBetween(st,et)
result = (td.Hours * 60) + (td.Minutes * 60) + td.Seconds
Return result
End Sub`
`Sub Delay (DurationMs As Int)
Dim target As Long = DateTime.Now + DurationMs
Do While DateTime.Now < target
Loop
End Sub`
BTW:
This is not a recommended routine for a delay as it blocks the main thread.
It is better to use a timer.

Changed: , Category: Application, File: T6C159M1154.htm, ID: 1154