[Lazarus] PostMessage return value
mschnell at lumino.de
Mon Sep 15 14:44:18 CEST 2014
On 09/15/2014 02:19 PM, Xiangrong Fang wrote:
> 2014-09-15 17:23 GMT+08:00 Michael Schnell <mschnell at lumino.de
> <mailto:mschnell at lumino.de>>:
> In that case I definitely would use Application.QueuAsyncCall.
> If I understand correct, from this page:
> 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?).
That is exactly what Postmessage does (in combination with procedure ...
In fact you don't need to call Application.ProcessMessages (on that
behalf). In fact (usually) the main thread is not supposed to do long
lasting or even polling loops to be made of run-to-completion events.
QueueAsyncCall just schedules another run-to-completion event for you
and same will automatically happen as soon as the main thread is free
(having done all previously scheduled events).
> 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.
Neither QueueAsyncCall nor Postmessage have anything to do with
finishing a thread (unless you call it right before the end of the
thread's execute procedure).
> Anyway, is PostMessage considered "deprecated" or "shall be used on
> windows only"?
Not really depreciated but IMHO (when used for thread to main thread
signaling) it's a relict from Delphi's widows-only heritage.
> Is there a better way to do what I want?
As said: you can do Application.QueueAsyncCall() right before the end of
the thread's execute procedure;
(Or you can simply start the new worker thread there instead of having
the main thread do this if this might be appropriate.)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Lazarus