[Lazarus] Multithreads for GUI use.

Mattias Gaertner nc-gaertnma at netcologne.de
Sun Nov 29 10:32:35 CET 2009


On Sat, 28 Nov 2009 22:05:26 -0500
Matt Shaffer <dazappa.matt at gmail.com> wrote:

> I was reading up on threads in FPC, and the wiki even mentioned them being
> used to prevent the GUI from locking up (which is what I wanted to do). I
> quickly stitched together the multithreaded example with my app (which is a
> simple image conversion program using fpimage), but the gui still hung when
> converting images, preventing the window from being moved and the progress
> bar from updating. I even made a thread whose sole purpose was to do
> Application.ProcessMessages every millisecond to ensure the darn thing would
> respond -- no luck.

The main thread must be the GUI thread.
If the main thread is busy, you can use Application.ProcessMessages.
Other threads should never use Application.ProcessMessages directly.
If other threads should effect some gui elements (read/write
properties), use Synchronize.

http://wiki.lazarus.freepascal.org/Multithreaded_Application_Tutorial

 
> So my question is: Does anyone have an actual example of preventing a GUI
> (currently on Windows) from locking up when executing a large chunk of code?
> Or does anyone feel like wading through my frankenstein code?


Mattias




More information about the Lazarus mailing list