For what it's worth...
This should also work:
static DateTime GetLastStartTime()
{
using (var Uptime = new System.Diagnostics.PerformanceCounter("System", "System Up Time"))
{
Uptime.NextValue();
return DateTime.Now.Subtract(TimeSpan.FromSeconds(Uptime.NextValue()));
}
}
It just doesn't require P/Invoke.
If you would like to use P/Invoke, here is an example of declaring GetTickCount (The usage is fairly straightforward... just call the function):
[System.Runtime.InteropServices.DllImport("kernel32", EntryPoint="GetTickCount", ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
public static extern int GetTickCount();
[System.Runtime.InteropServices.DllImport("kernel32", EntryPoint="GetTickCount64", ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
public static extern long GetTickCount64();
Wasabi Fan
No comments:
Post a Comment