-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathMethodsWithTimestampPreweaved.cs
More file actions
46 lines (42 loc) · 1.32 KB
/
MethodsWithTimestampPreweaved.cs
File metadata and controls
46 lines (42 loc) · 1.32 KB
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
37
38
39
40
41
42
43
44
45
46
namespace ExampleAssembly
{
using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;
public class MethodsWithTimestampPreweaved
{
private long _startTimestamp = default;
private long _endTimestamp;
private long _elapsed;
private TimeSpan _elapsedTimeSpan;
private int _state = 0;
private string methodTimerMessage;
public async Task AsyncMethod()
{
if (_startTimestamp == 0)
{
_startTimestamp = Stopwatch.GetTimestamp();
}
try
{
await Task.Delay(5);
}
finally
{
StopMethodTimerStopwatch();
}
}
private void StopMethodTimerStopwatch()
{
if (_state == -2 && _startTimestamp != 0)
{
_endTimestamp = Stopwatch.GetTimestamp();
_elapsed = _endTimestamp - _startTimestamp;
_elapsedTimeSpan = new TimeSpan((long)(MethodTimerHelper.TimestampToTicks * (double)_elapsed));
methodTimerMessage = null;
MethodTimeLogger.Log(MethodBase.GetCurrentMethod(), (long)_elapsedTimeSpan.TotalMilliseconds, methodTimerMessage);
}
}
}
}