C#自己写的delay延时函数

xtzy89 2013-11-07 06:20:46
[code=csharp]static void Delay(uint ms) {
uint start = GetTickCount();
while (GetTickCount() - start < 1000ms) {
Application.DoEvents();
}
}


GetTickCount()是获取的开机时间吗?GetTickCount()-start指的是什么?
如果是当前时间-开机的时间怎么会小于1000ms呢?
如:8:00am开机,现在是9:00am==》GetTickCount()-start该如何理解?是一个小时的毫秒数吗?
菜鸟请求大神帮忙解答,感谢![/code]
...全文
1137 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xtzy89 2013-11-08
  • 打赏
  • 举报
回复
引用 2 楼 wind_cloud2011 的回复:
GetTickCount()用于获取自windows启动以来经历的时间长度(毫秒) ,是一个可以继续响应操作,而且精度高的延时函数, gettickcount()精确到55ms(1个tick就是55ms) using System.Runtime.InteropServices; [DllImport("kernel32.dll")] static extern uintGetTickCount(); http://www.4fang.net/D4/29627.html
GetTickCount()返回的是从开机到现在这段时间的毫秒数吗?我刚开始理解是开机那个时间点了。 今天差了下,好像是时间段,如果这样,我就可以理解了。
wind_cloud2011 2013-11-07
  • 打赏
  • 举报
回复
在执行下一步操作之前,需要等待上一步的执行完成,这个等待时间就是Delay(uint ms),如是Delay(1000)搂你提供就是等待1000*1000 MS (你那要修改为GetTickCount() - start < 1000*ms) http://www.4fang.net/D4/29627.html ,这里有详细说明,
wind_cloud2011 2013-11-07
  • 打赏
  • 举报
回复
GetTickCount()用于获取自windows启动以来经历的时间长度(毫秒) ,是一个可以继续响应操作,而且精度高的延时函数, gettickcount()精确到55ms(1个tick就是55ms) using System.Runtime.InteropServices; [DllImport("kernel32.dll")] static extern uintGetTickCount(); http://www.4fang.net/D4/29627.html
threenewbee 2013-11-07
  • 打赏
  • 举报
回复
1000ms -> 1000 * ms 否则根本都编译不了。

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧