1. Computing
in Delphi Threading :: To speed up data processing in your application you can decide to include one or more "secondary" threads. When several threads are running in the application a question arises: how to update your GUI (user interface) as a result of a thread execution. The question lies in the TThread class Synchronize method.

Read the full article to learn about Synchronizing Threads and GUI in Delphi application

Related:

Comments
April 14, 2011 at 6:25 am
(1) andy says:

i have a question,
and how to update your running thread as a result of a GUI

April 14, 2011 at 7:32 am
(2) Olaf Monien says:

Your article suggests that “synchronize” is the only and ultimate way of synchronizing the UI with threads. This is simply not true and there are scenarios where this synchronize attempt will just fail.
Think of many threads trying to synchronize or just one thread calling synchronize with a high frequency – the reason for applications with stalled UIs. You could solve that with some logic that limits the calls to synchronize, but with more than one thread this will lead to pure mess. Often a better solution is to use Timers …

April 14, 2011 at 11:54 am
(3) Warren P. says:

Synchronize is this hammer, that every Delphi developer uses, and thinks that every thread problem is a nail. This is a terrible disease in the delphi programmer community. There is a crying need to learn about monitors, critical sections, and even using simple async non-blocking techniques like PostMessage, to avoid the huge problems, of using Synchronize a lot. Sure it works great in demo apps. But a lot of delphi coders seem to try to take their demo-app technique and scale that up to production real-world software, and it makes a mess!

Warren P.

April 14, 2011 at 12:38 pm
(4) Jens Borrisholt says:

I wrote the code. I know about PostMessage CriticalSections etc.

This is small example to get started with multithread. This wasn’t ment as an example of a large scale application …

type
TThreadExaple = class(TSmallExample, iThreadApplication);

;o)

April 17, 2011 at 3:56 pm
(5) Ajasja Ljubetic says:

@ Jens: I agree with Olaf and Warren, you could have at least mentioned the other methods as well.
There are also great multi threading libraries out there that can take care of this problem.

http://andy.jgknet.de/blog/bugfix-units/asynccalls-29-asynchronous-function-calls/

http://code.google.com/p/omnithreadlibrary/

April 20, 2011 at 5:19 am
(6) Michael Schnell says:

Sorry to disagree with the article but in fact it is silly to use “Synchronize” to set a progress bar (or similar quite asynchronous stuff necessarily done in the GUI thread), as Synchronize stalls the worker thread for an unforeseeable amount of time. If this is not a problem, you don’t need to use a thread at all.

Happily since some years Delphi provides TThread.Queue for exactly this purpose: it schedules a procedure as an event in the GUI thread, but does not stall the worker thread.

But of course you need to take care of mutual access problems when using TThread.Queue, as the thread keeps on running. Supposedly this is why they chose to drop TThreadf.Queue in the Delphi help.

-Michael

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2014 About.com. All rights reserved.