Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-11

Multithreads for GUI use.

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Matt Shaffer

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.

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? -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20091128/b00945c1/attachment.html>

Reply by email

Mattias Gaertner
to Matt Shaffer
Show quoted text 8 lines
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

Reply by email

Matt Shaffer
to Mattias Gaertner

I was using synchronize, but as I figured out today, I was using it incorrectly. With a bit of fiddling today I managed to get it working; both with the progress bar updating and the GUI not hanging. Thanks.

On Sun, Nov 29, 2009 at 4:32 AM, Mattias Gaertner <

Show quoted text 42 lines
wrote: On Sat, 28 Nov 2009 22:05:26 -0500 Matt Shaffer 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 -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20091129/83c53b06/attachment-0001.html>

Reply by email