使用timeSetEvent应注意事项

1、timeSetEvent最长时间间隔不能超过1000秒,即1000000毫秒,超过返回失败,可用CreateTimerQueryTimer或SetTimer(回调的方式)代替

2、timeSetEvent会生成一个独立的Timer回调线程,属多线程

3、timeSetEvent可创建高精度定时器,精确到1ms,SetTimer无法精确到1ms

4、timeKillEvent关掉定时器的函数,一定要一一对应,每次timeSetEvent返回的定时器的ID是不一样的,调用一次timeSetEvent就会产生一次Id,调用了几次timeSetEvent,就需要调用几次timeKillEvent ,而且必须是相对应的ID,否则可能出现程序崩溃!

5、最重要一点,也是经常范的错误;系统对timeSetEvent数量是有限制的,一个进程最多只能创建30个timeSetEvent,超过会返回失败

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
在 Delphi 11 64位中使用 timeSetEvent 函数可能会遇到一些问题,因为该函数是32位 Windows API 的一部分,而 Delphi 11 64位是基于 64位 Windows API 的。 为了在 Delphi 11 64位中使用 timeSetEvent 函数,你需要使用一个代替方案。一个可用的代替方案是使用 CreateTimerQueueTimer 函数。这个函数可以创建一个定时器,并在指定的时间间隔内重复调用一个回调函数。 以下是一个使用 CreateTimerQueueTimer 函数的示例代码: ``` var TimerQueue: THandle; TimerHandle: THandle; procedure TimerCallback(lpParameter: Pointer; TimerOrWaitFired: Boolean); begin // 处理定时器触发后的事件 end; // 创建定时器 procedure CreateTimer; begin TimerQueue := CreateTimerQueue; if TimerQueue <> 0 then begin // 创建定时器 if not CreateTimerQueueTimer(TimerHandle, TimerQueue, @TimerCallback, nil, 1000, 1000, 0) then RaiseLastOSError; end else RaiseLastOSError; end; // 销毁定时器 procedure DestroyTimer; begin DeleteTimerQueueTimer(TimerQueue, TimerHandle, INVALID_HANDLE_VALUE); DeleteTimerQueue(TimerQueue); end; ``` 在上面的代码中,我们首先使用 CreateTimerQueue 函数创建一个定时器队列。然后使用 CreateTimerQueueTimer 函数创建一个重复触发的定时器,并指定回调函数 TimerCallback。在回调函数中,我们可以处理定时器触发后的事件。最后,在程序退出时,我们调用 DeleteTimerQueueTimer 和 DeleteTimerQueue 函数销毁定时器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wangwb136

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值