سؤال

I have an ActiveX control in a Delphi project. It features a function that calculates certain value. The trouble is that the result of calculation is provided in an event that is triggered asynchronously.

I would rather prefer to make a call to this function and to wait until it finishes, then to proceed with the program (sync call).

I tried using a thread, but that did not trigger the event due to unknown reason. Furthermore, I am not sure if it is thread safe to use the control in this way.

Are there any general guidelines how to safely convert an AX async method to a sync method?

هل كانت مفيدة؟

المحلول

Create a TEvent that is initially unsignaled. Signal it in the asynchronous event handler. Wait for it to become signaled after starting the asynchronous operation. Depending on the COM object's threading model, you might need to pump the message queue periodically to get the asynchronous event to trigger.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top