VB6 killing timers

夙愿已清 提交于 2019-12-24 01:01:33

问题


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.

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.

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.

Is there a way of killing a VB6 timer? If not whats the best way to avoid infinite loops?

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


回答1:


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


来源:https://stackoverflow.com/questions/41446618/vb6-killing-timers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!