【发布时间】: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(互操作),然后在正确的时刻处理事件。
【问题讨论】: