Hi I am following the tutorial COM APIs for use in Microsoft Office and looking at Tutorial 2 AdxRtList. I understand that after the function is called with .StartUpdates in myRtGetExample then the result is returned asynchronously via callback to the myRtGet_OnImage function. I can see this might be appropriate if e.g. updating a spreadhsheet while you keep working in it. But if you are running some code and need the AdxRtList result BEFORE proceeding any further, how do you "make it synchronous"? I have stumbled on something which seems to work but don't know if it's the correct approach. The idea is to have a Boolean module level variable called task_finished_ which I set to false before the AdxRtList call and then loop after the call until task_finished_ = True. Meanwhile the callback myRtGet_OnImage sets task_finished_ = True before exiting.
Dim WithEvents myRTGet As AdfinXRtLib.AdxRtList Private task_finished_ As Boolean Sub myRtGetExample() task_finished_ = False Set myRTGet = CreateAdxRtList() With myRTGet Source = "IDN" .RegisterItems "EUR=", "BID" .StartUpdates RT_MODE_IMAGE End With While Not task_finished_ Sleep 1000 DoEvents Wend End Sub Private Sub myRtGet_OnImage(ByVal DataStatus As AdfinXRtLib.RT_DataStatus) Debug.Print myRTGet.Value("EUR=", "BID") task_finished_ = True End Sub
As I said, it seems to work but I don't know if that's the right way to do it or if there is a better approach ... Thanks
@george34 yep, that's one of the approaches. It depends on your task, of course, but I would still recommend using it asynchronously most of the time.
As an example of broad async approach, check out this article.