blob: 4c47906922ccaac54b1381a5ca1f6e4a98382abb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
using System;
using System.Diagnostics;
namespace QtVsTools
{
public class ConcurrentStopwatch : Concurrent<ConcurrentStopwatch>
{
Stopwatch Stopwatch { get; }
public ConcurrentStopwatch()
{
Stopwatch = new Stopwatch();
}
public static ConcurrentStopwatch StartNew()
{
ConcurrentStopwatch s = new ConcurrentStopwatch();
s.Start();
return s;
}
public static long Frequency => Stopwatch.Frequency;
public static bool IsHighResolution => Stopwatch.IsHighResolution;
public bool IsRunning => ThreadSafe(() => Stopwatch.IsRunning);
public TimeSpan Elapsed => ThreadSafe(() => Stopwatch.Elapsed);
public long ElapsedMilliseconds => ThreadSafe(() => Stopwatch.ElapsedMilliseconds);
public long ElapsedTicks => ThreadSafe(() => Stopwatch.ElapsedTicks);
public void Reset() => ThreadSafe(() => Stopwatch.Reset());
public void Restart() => ThreadSafe(() => Stopwatch.Restart());
public void Start() => ThreadSafe(() => Stopwatch.Start());
public void Stop() => ThreadSafe(() => Stopwatch.Stop());
}
}
|