本文介绍了在没有 DoEvents 的情况下取消 VB6.0 中长时间运行的进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不使用 DoEvents 的情况下取消 VB6.0 中长时间运行的进程?

Is it possible to cancel out of a long running process in VB6.0 without using DoEvents?

例如:

for i = 1 to someVeryHighNumber
    ' Do some work here '
    ...

    if cancel then
        exit for
    end if
next

Sub btnCancel_Click()
    cancel = true
End Sub

我想在如果取消然后..."之前我需要一个DoEvents"有没有更好的方法?好久不见...

I assume I need a "DoEvents" before the "if cancel then..." is there a better way? It's been awhile...

推荐答案

不,你没看错,你肯定希望在循环中使用 DoEvents.

Nope, you got it right, you definitely want DoEvents in your loop.

如果您将 DoEvents 放在主循环中并发现它减慢了太多处理速度,请尝试调用 Windows API 函数 GetQueueStatus(比 DoEvents 快得多)快速确定是否有必要调用 DoEvents.GetQueueStatus 告诉您是否有任何事件要处理.

If you put the DoEvents in your main loop and find that slows down processing too much, try calling the Windows API function GetQueueStatus (which is much faster than DoEvents) to quickly determine if it's even necessary to call DoEvents. GetQueueStatus tells you if there are any events to process.

' at the top:
Declare Function GetQueueStatus Lib "user32" (ByVal qsFlags As Long) As Long

' then call this instead of DoEvents:
Sub DoEventsIfNecessary()
    If GetQueueStatus(255) <> 0 Then DoEvents
End Sub

这篇关于在没有 DoEvents 的情况下取消 VB6.0 中长时间运行的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 16:50