VBA - RHistory events cancelled by MsgBox

Hello, i notice that events "OnImage" and "OnUpdate" are not triggered if a MsgBox is used right after RHistoryQuery.Subscribe. Did you know about this issue ? How can i solve this problem ?

Best Answer

  • RHistory API gets the data asynchronously, so if you block the execution of the current thread with the MsgBox, the fired event will be missed. I think you will see same behaviour with any async API.

    I suggest either queuing the 'Subscribe' call after the MsgBox call, or refrain from using MsgBox at all.

Answers

  • To add to the answer by @Zhenya Kovalyov, as an alternative to VBA message box, which is modal and which blocks the execution thread, you can use Win API message box where you can control the modality. Attached is a quick example.nonmodalmessagebox.zip

  • Hello thanks both for your answers.

    I found an other alternative -> I set the request frequency to 1 seconde.

    The event OnUpdate will be trigerred every 1 seconde. So, even if a MsgBox block the execution, the event will still be called right after the end of the MsgBox.

    To avoid multiple execution, i also cancel the request in the event OnUpdate.

  • @francois.binot
    From what you're saying it seems that your goal is to retrieve the timeseries once after the request and not to receive any subsequent updates to the timeseries, right? If this is the case you can use "FRQ:SNAP" in RefreshParams property of RHistoryQuery object. Then you will not need to cancel the request after you receive the initial image nor to handle OnUpdate event at all. The timeseries will be delivered into OnImage event as a snapshot. And OnUpdate event will never be raised.