Environment.TickCount is not enough

后端 未结 6 1042
别那么骄傲
别那么骄傲 2021-01-13 11:50

I want to know on when was the last time the system was started.

Environment.TickCount will work but it is breaking after 48-49 days because of the limitation of int

6条回答
  •  余生分开走
    2021-01-13 12:19

    The following code retrieves the milliseconds since system start (call to unmanged API). I measured the performance costs for that interop operation, and it is quite identical to StopWatch() (but that doesn't retrieve the time since system start directly of course).

    using System.Runtime.InteropServices;
    

    ...

    [DllImport("kernel32.dll") ]
    public static extern UInt64 GetTickCount64();
    

    ...

    var tickCount64 = GetTickCount64();
    

    https://msdn.microsoft.com/de-de/library/windows/desktop/ms724411(v=vs.85).aspx

提交回复
热议问题