请看如下:
using System.Diagnostics;
using System.Runtime.InteropServices;
[DllImport("kernel32.dll")]
static extern uint GetTickCount();
static void Delay(uint ms)
{
uint start = GetTickCount();
while(GetTickCount() - start <ms)
{
Application.DoEvents();
}
} 使用方法如下:
uint ms = 200;
Delay(ms);大家猜猜这个有什么用?咔咔咔,简直就是优雅至极!
本文介绍了一种在C#中实现精确延时的方法,通过调用GetTickCount()获取当前时间戳,并在一个循环中检查时间差是否达到指定毫秒数来实现。此方法适用于需要短时间精确延时的场合。
1万+

被折叠的 条评论
为什么被折叠?



