WinPeriod.cs 605 B

123456789101112131415161718192021
  1. using System.Runtime.InteropServices;
  2. namespace ET
  3. {
  4. public static class WinPeriod
  5. {
  6. // 一般默认的精度不止1毫秒(不同操作系统有所不同),需要调用timeBeginPeriod与timeEndPeriod来设置精度
  7. [DllImport("winmm")]
  8. private static extern void timeBeginPeriod(int t);
  9. //[DllImport("winmm")]
  10. //static extern void timeEndPeriod(int t);
  11. public static void Init()
  12. {
  13. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  14. {
  15. timeBeginPeriod(1);
  16. }
  17. }
  18. }
  19. }