简体   繁体   English

COM(VB6)事件在AutoIt中有延迟处理

[英]COM (VB6) events are handled with a delay in AutoIt

I have an AutoIt script that uses a COM-object (created with VB6). 我有一个使用COM对象(使用VB6创建)的AutoIt脚本。 The COM-object can fire events. COM对象可以触发事件。 I would like to use these events to display progress of a task in the AutoIt script, because the execution of the VB6 task can take up to 10 minutes. 我想使用这些事件在AutoIt脚本中显示任务的进度,因为执行VB6任务可能需要10分钟。 The problem is that the events are being fired, but that they are handled in AutoIt after the processing of the 'huge' task has ended. 问题在于事件正在被触发,但是在“巨大”任务的处理结束后才在AutoIt中对其进行处理。 Below you can find a reduced version of the script. 在下面可以找到该脚本的简化版本。 In the real-life version of the script a GUI is used and the progress percentage should not be written to the console, but to the inner text of a 'DIV' element. 在脚本的实际版本中,使用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

The 'CreateReport' method of the COM-object fires the event two times before actually starting the 'huge' task itself. COM对象的“ CreateReport”方法在实际启动“巨大”任务本身之前触发两次该事件。 However, the messages for these events only will be written to the console after the rendered HTML is written to the console. 但是,仅在将渲染的HTML写入控制台后,这些事件的消息才会写入控制台。

Can anybody help me to make sure that the events are handled within the AutoIt script at the correct moment (during execution of the 'huge' task)? 有人可以帮助我确保在正确的时间(在执行“巨大”任务期间)在AutoIt脚本中处理事件吗?

Thanks in advance! 提前致谢!

Björn 比约恩

PS I made a reference implementation in C# which uses the same VB6 (Interop) and then the events are handled at the right moment. PS我在C#中做了一个参考实现,它使用相同的VB6(互操作),然后在适当的时候处理事件。

It appears that this is a 'habbit' of the current live version (3.3.8.1) of AutoIt. 看来这是AutoIt当前实时版本(3.3.8.1)的“习惯”。 The current beta-version (3.3.9.25) supports the 'volatile' keyword. 当前的beta版本(3.3.9.25)支持'volatile'关键字。 When this keyword is used, the event handling function is called synchronous (according to the manual). 使用此关键字时,事件处理功能称为同步(根据手册)。 Anyway, this solves the problem. 无论如何,这解决了问题。 Unfortunately, I cannot allow myself to use an unstable version of AutoIt, but my question has been solved (thanks to Trancexx on the AutoIt forum). 不幸的是,我不能让自己使用不稳定版本的AutoIt,但我的问题已解决(感谢AutoIt论坛上的Trancexx)。

Volatile Func ToolsEvent_OnTaskProgressChange($taskProgress)

    ConsoleWrite('Progress(%): ' & $taskProgress & @CRLF)

EndFunc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM