-4

Need a high-precision timestamp .NET function

I have used winapi TimeGetTime. But it uses Int32, cycles every 49.8 days and return can be signed.

What is a native .NET high-precision function which return type is Int64 or UInt64, returns milliseconds?

It is not important whether it returns milliseconds from system start or any other time in the past.

Actually I don't need StopWatch

EDIT:
My application is multithreaded. StopWatch instance should be created for every thread. StopWatch has a very high-precision timer. I need only 1-5ms. What I need is something like timeGetTime / Environment.TickCount as Int64 or DateTime.Ticks with update resolution of 1-5ms

4

2 に答える 2

1

Windows 8 または Server 2012 以降を使用GetSystemTimePreciseAsFileTimeしている場合は、次のように使用します。

[DllImport("Kernel32.dll", CallingConvention = CallingConvention.Winapi)]
static extern void GetSystemTimePreciseAsFileTime(out long filetime);

public DateTimeOffset GetNow()
{
    long fileTime;
    GetSystemTimePreciseAsFileTime(out fileTime);
    return DateTimeOffset.FromFileTime(fileTime);
}

これは よりもはるかに優れた精度を持っていますDateTime.UtcNow.Ticks

詳細については、MSDN を参照してください: http://msdn.microsoft.com/en-us/library/windows/desktop/hh706895(v=vs.85).aspx

于 2014-12-02T21:03:58.233 に答える
0

DateTime.UtcNow.Ticks を使用できます。これは実際にはミリ秒よりも正確です。

于 2013-01-17T19:24:47.670 に答える