【问题标题】:COM (VB6) events are handled with a delay in AutoItCOM (VB6) 事件在 AutoIt 中延迟处理
【发布时间】:2019-02-14 11:22:45
【问题描述】:

我有一个使用 COM 对象(用 VB6 创建)的 AutoIt 脚本。 COM 对象可以触发事件。我想使用这些事件在 AutoIt 脚本中显示任务的进度,因为 VB6 任务的执行可能需要长达 10 分钟。问题是事件正在被触发,但是在“巨大”任务的处理结束后它们在 AutoIt 中处理。您可以在下面找到该脚本的简化版本。在脚本的真实版本中使用了 GUI,进度百分比不应写入控制台,而应写入“DIV”元素的内部文本。

Work()

Func Work()
    Local $g_oReport = ObjCreate("wcDashboardTools.DashBoardToolsVB6")

    If IsObj($g_oReport) Then
        $g_oReport.Server = "my-sql-server-name"

        Local $g_oReportEvents = ObjEvent($g_oReport,"ToolsEvent_") ; Start receiving Events.

        ; Test the events three times (the 'InitEvents' methods only raises the event in VB6).
        $g_oReport.InitEvents()
        Sleep(3000)

        $g_oReport.InitEvents()
        Sleep(3000)

        $g_oReport.InitEvents()

        ; In the test application this works and the event messages now have been written
        ; to the console. In the real life application, these 'test' messages will
        ; only be written to the console after the report results have been rendered.
        $g_oReport.Database             = "my-database-name"
        $g_oReport.FinancialYear        = 2013
        $g_oReport.FinancialPeriodStart = 1
        $g_oReport.FinancialPeriodEnd   = 1
        $g_oReport.ReportLayout         = "my-layout-name"

        ; Start the huge task.
        $g_oReport.CreateReport()

        ; At this point, the huge task has been completed.
        ConsoleWrite("Creation of the report finished, start rendering the report")

        If @Compiled = 0 Then $g_oReport.StoreReportAsXml("c:\temp\exploreport.xml")

        ; Start rendering.
        $sHTML = $g_oReport.GetReportAsHtmlString()
        ConsoleWrite($sHTML)
    Else
        ConsoleWrite("FOUT: Het genereren van de rapportage is mislukt.")
    EndIf
EndFunc

COM 对象的“CreateReport”方法会在实际启动“巨大”任务本身之前触发该事件两次。但是,这些事件的消息只有在渲染的 HTML 写入控制台后才会写入控制台。

谁能帮助我确保在正确的时刻(在执行“巨大”任务期间)在 AutoIt 脚本中处理事件?

提前致谢!

比约恩

附:我在 C# 中做了一个参考实现,它使用相同的 VB6(互操作),然后在正确的时刻处理事件。

【问题讨论】:

    标签: events com autoit


    【解决方案1】:

    这似乎是 AutoIt 当前实时版本 (3.3.8.1) 的“习惯”。当前的 beta 版本 (3.3.9.25) 支持 'volatile' 关键字。使用此关键字时,事件处理函数称为同步(根据手册)。无论如何,这解决了问题。不幸的是,我不能让自己使用不稳定版本的 AutoIt,但我的问题已经解决(感谢 AutoIt 论坛上的 Trancexx)。

    Volatile Func ToolsEvent_OnTaskProgressChange($taskProgress)
    
        ConsoleWrite('Progress(%): ' & $taskProgress & @CRLF)
    
    EndFunc
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      • 2021-09-25
      • 2021-10-05
      • 1970-01-01
      • 2013-09-08
      • 1970-01-01
      相关资源
      最近更新 更多