I have to execute some code in the context of the main thread. I am using Lazarus + FPC. I receive an event from a thread inside a DLL (shared library if on linux) and my callback function gets called. Note that this function is not a member of any class but a standalone traditional function with a "cdecl" directive attached.
I have to triger a coresponding property event handler for each such message I receive. And these events have to be passed on in the context of the main thread. I know of two such solutions:
- PostMessage
- Application.QueueAsyncCall
The first one is ok, but it requires a window handle. And since this is a library code no handle is available. AllocateHWND is not an option since it is not cross platform. I know I can create a dummy form but this is a very bad solution
The second works ok, but I have a problem, that the call is not processed until I move a mouse inside application for instance. Maybe I am doing something wrong I don't know. I is just like my call is being processed only when message processing kicks in. But this can be a long wait apparently.
So I want to know what is the best solution here (probably QueueAsyncCall) and how I can be sure that my message (call) will be processed in acceptable timeframe?