Environment.TickCount is not enough
- Environment.TickCount will overflow after approximately 25 days, because the return value is a 32-bit integer.
- https://stackoverflow.com/questions/756462/elapsed-time-with-environment-tickcount-avoiding-the-wrap
Use Stopwatch
Stopwatch mStopwatch = new Stopwatch();
mStopwatch.Start();
long elapsedMs = mStopwatch.ElapsedMilliseconds;
- https://stackoverflow.com/questions/4645171/environment-tickcount-is-not-enough/4645208
Use GetTickCount64
This function does the same as GetTickCount but returns the result as a 64 bit integer.
Please note that the function result wraps to 0 after about 584 million years.
- https://docs.microsoft.com/ko-kr/windows/desktop/api/sysinfoapi/nf-sysinfoapi-gettickcount64
using System.Runtime.InteropServices;
...
[DllImport("kernel32.dll") ]
public static extern UInt64 GetTickCount64();
...
var tickCount64 = GetTickCount64();
최근댓글