[Lazarus] PostMessage return value

Sven Barth pascaldragon at googlemail.com
Mon Sep 15 14:34:00 CEST 2014


Am 15.09.2014 14:21 schrieb "Xiangrong Fang" <xrfang at gmail.com>:
>
> 2014-09-15 17:23 GMT+08:00 Michael Schnell <mschnell at lumino.de>:
>>
>>
>> In that case I definitely would use Application.QueuAsyncCall.
>
>
> If I understand correct, from this page:
>
> http://wiki.freepascal.org/Asynchronous_Calls
>
> QueueAsyncCall is, like what its name suggest, doing this in asynchronous
favor -- it execute queued method in the next message loop (while
Application.ProcessMessages takes place, right?).
>
> But what I need PostMessage for is to notify main thread (or another
thread) that a worker thread finished its job, so that the thread manager
can start a new thread to do the remaining work.

PostMessage is asynchronous as well. For a synchronous way I'd suggest you
to take a look at TThread.Synchronize and corresponding documentation and
tutorials.

Note: Synchronize can only notify the main thread.
Note2: The synchronous alternative to PostMessage would be SendMessage,
though I don't know whether Lazarus provides this in a cross platform way

If you want to use a separate thread ("dispatcher") for enqueueing new work
you should create an event that you pass to this thread and the worker
threads. The dispatcher waits on the event and the worker threads will
signal the event once they are done. Of course you'll likely also signal
the event when new work items are queued that need to be dispatched.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140915/21ddb978/attachment-0003.html>


More information about the Lazarus mailing list