WinRT Replacement of System.Environment.TickCount

2019-04-21 15:38发布

问题:

What is the WinRT replacement for System.Environment.TickCount?

回答1:

It should be available, because it isn't a problem. But it is not, a [TypeForwardedTo] hangup I guess because GetTickCount() isn't on the white list and .NET never adopted GetTickCount64. The standard fallback works fine, you can use pinvoke the call the native Windows function. I verified that a program that uses it passes the Windows App Certification Kit test.

    [System.Runtime.InteropServices.DllImport("kernel32.dll")]
    private static extern long GetTickCount64();

Note that it returns a long, not an int. You can simply cast to int to truncate if that's important in C# (but not vb.net, just lie about the return type)



回答2:

It appears System.Environment.TickCount is supported in Windows 8 Windows store apps now.