?
Solved

Better alternative to Application.ProcessMessages?

Posted on 2009-12-18
3
Medium Priority
?
708 Views
Last Modified: 2012-05-08
Hello,
My first question, so I hope I am doing it correctly!  I'm not sure how much or how little detail to give...

I need some guidance - I have a list of tasks that must be performed in order. Each task instruction is sent to a separate worker thread for processing. The sequence must wait for the preceding task to complete before moving on to the next one. I currently have a flag set by the worker thread when the task is done, and the list waits for this flag in an "application.processmessages" loop, before moving on to the next task.  It works, but I can't help but feel there is a better way.  Can someone suggest a better approach?
0
Comment
Question by:GVP
3 Comments
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 26080732
the best is to not use it at all

have you checkec omni thread library yet by delphi geek ?
this has a system with worker threads and a system for ordering the threads executing

www.delphigeek.com
http://17slon.com/blogs/gabr/2009/11/omnithreadlibrary-patterns-task.html
0
 
LVL 12

Accepted Solution

by:
Hypo earned 200 total points
ID: 26080745
I can think of two ways...
1:
There is an event in the TThread base class which is called OnTerminate... this event is triggered from the main thread, when the execute mehod of the thread finishes... hence, it is safe to place this eventhandler in the main form of your applicaiton... So, whenever the event fires, you can start start the next thread in the list.

2:
If your threads are not constructed in a way that makes them terminate when they are finished, but instead they just set a flag and continue ruinning, then you can acheive a similar functionality as in the first case by adding a TNotifyEvent to your thread class, along with a function to trigger this event... you then set an event handler in your main form, and whenever the thread is finished with it's calculations, you call the trigger function using the Synchronize procedure, which will make it execute from the main thread... the eventhandler itself will then start the next thread in the list...

with these methods you never have to keep a loop in your main form that calls application.process messages, so you can leave that to the message pump...

/Hypo
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 26080771
Can't let the worker threads fire an event when they're done which you process in the main thread?
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question