VB6 杀死定时器 [英] VB6 killing timers

查看:49
本文介绍了VB6 杀死定时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 VB6 进行编程,因为我们使用的是遗留代码和硬件(外部电子设备).

I'm programming in VB6 because we are using legacy code and hardware (external electronics).

我的程序是围绕计时器构建的,我将在其中使用操作系统编程中的任务.计时器一直在运行,直到它们的工作完成.设置一个标志并启动另一个计时器.

My programs are build around timers where I would use tasks in OS programming. The timers are running until their job is done. A flag is set and another timer is started.

我想要一个监控其他计时器的监控计时器当计时器没有产生任何结果或正在等待一个永远不会发生的真实世界事件(Do while 循环)时,我想终止计时器.在电子产品中,我们有一个看门狗计时器",它检查代码是否仍在运行(并产生结果).我想在VB6中做一个看门狗定时器.

I want a supervisory timer that controllers the other timers When the timers produce no result or are waiting for a real world event that never comes (Do while loop) I want to kill the timer. In electronics we have a 'watch dog timer' it checks if the code is still running (and producing results). I want to do a watch dog timer in VB6.

vb6 中的定时器有 Timer.interval 和 Timer.enabled.我无法使用这些工具终止计时器.我可以禁止计时器启动.我知道几种杀死循环的方法.就像计算圈数并在达到最大值时爆发.甚至检查检查标志.

Timers in vb6 have Timer.interval and Timer.enabled. I'm unable to kill the timer with these tools. I can prohibit a timer from starting. I know of a few ways to kill a loop. Like counting the laps and breaking out when the maximum is reached. Or even checking checking a flag.

有没有办法杀死 VB6 定时器?如果不是,避免无限循环的最佳方法是什么?

附带问题:有没有办法列出正在运行的计时器?

Side question: Is there a way of listing what timers are running?

推荐答案

您已经回答了您自己的问题,将 .enabled 设置为 false 将阻止下一个间隔触发.

You have answered you own question, setting .enabled to false will prevent the next interval from firing.

要在其间隔已经运行时终止"计时器,您需要检查标志并退出正在运行的方法中.(没有其他方法,因为所有这些都发生在一个线程上)

To "kill" the timer when its interval is already running you would need to check for a flag and exit within the running method/s. (There is no other way as all of this is happening on a single thread)

有没有办法列出正在运行的计时器?

Is there a way of listing what timers are running?

Dim ctrl As VB.Control
For Each ctrl In Me
    If TypeOf ctrl Is VB.Timer Then
        Debug.Print ctrl.Name, "running: "; ctrl.Enabled And ctrl.Interval > 0
    End If
Next

这篇关于VB6 杀死定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆