DelphiFAQ Home Search:
General :: Programming :: Delphi :: VCL
About the Delphi VCL (Visual Component Library)

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Only the 40 most recently viewed articles are shown.
You can see the full list here.

Featured Article

Avoiding Application.ProcessMessages

Q:
I am writing a procedure, which may take a long time to execute. I want
the user to be able to stop it at any point of execution. I can use
Application.ProcessMessages to handle a click of the 'STOP' button.
I also thougt about creating a new thread for the procedure.
In either case I have to check for a variable 'ProcedureStopped' (with
Application.ProcessMessages) or I have to check for MyThread.Terminated.

Both of these require frequent polling. I'd prefer some kind of
interrupt to exit the procedure.

A:
By Hallvard Vassbotn, hallvard@millionhandshakes.com :

Unfortunately, by default the VCL does not have a very thread-friendly
mainthread message loop. It is possible to override the message loop by
hooking Application.OnIdle and call MsgWaitForMultipleObjects there.
Doing this you can build your own multithread aware message loop and
thus easiliy get notified of events and other signals raised from
secondary threads.


Generated 8:02:08 on Jan 21, 2019