Skip to content

Commit 0de338d

Browse files
committed
Time measuring changed
1 parent 556e060 commit 0de338d

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

Source/NETworkManager/ViewModels/Applications/PingViewModel.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class PingViewModel : ViewModelBase
2626
CancellationTokenSource cancellationTokenSource;
2727

2828
DispatcherTimer dispatcherTimer = new DispatcherTimer();
29+
Stopwatch stopwatch = new Stopwatch();
2930

3031
private bool _isLoading = true;
3132

@@ -272,12 +273,15 @@ private async void StartPing()
272273
{
273274
IsPingRunning = true;
274275

276+
// Measure the time
275277
StartTime = DateTime.Now;
276-
Duration = new TimeSpan();
278+
stopwatch.Start();
277279
dispatcherTimer.Tick += DispatcherTimer_Tick;
278280
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
279281
dispatcherTimer.Start();
280282
EndTime = null;
283+
284+
// Reset the latest results
281285
PingResult.Clear();
282286
PingsTransmitted = 0;
283287
PingsReceived = 0;
@@ -358,7 +362,7 @@ private async void StartPing()
358362

359363
private void DispatcherTimer_Tick(object sender, EventArgs e)
360364
{
361-
Duration = (DateTime.Now - (DateTime)StartTime);
365+
Duration = stopwatch.Elapsed;
362366
}
363367

364368
private void StopPing()
@@ -370,9 +374,15 @@ private void StopPing()
370374
private void PingFinished()
371375
{
372376
IsPingRunning = false;
377+
378+
// Stop timer and stopwatch
379+
stopwatch.Stop();
373380
dispatcherTimer.Stop();
381+
382+
Duration = stopwatch.Elapsed;
374383
EndTime = DateTime.Now;
375-
Duration = (DateTime)EndTime - (DateTime)StartTime;
384+
385+
stopwatch.Reset();
376386
}
377387

378388
public void OnShutdown()

0 commit comments

Comments
 (0)