Jump to content
Sign in to follow this  
uligerhardt

Simole threads providing progress info

Recommended Posts

Hi all!

 

I have some kind of dashboard/action central that provides a host of different buttons. All of these start an independent task and display progress info about that task (in a tree view). Currently this is handled without threading, so the dashboard is blocked until the task is finished.

Therefore I'd like to make these tasks into threads.  What threading library would you recommend? TThread, Andreas Hausladen's AsyncCalls, OmniThread or something different?

Share this post


Link to post

I would recommend to use only that threading library not the others you will save a lot of time.

 

A more serious answer is that you should give us more details. Anyo of those can create a thread which library to choose really depends on the requirements.

Share this post


Link to post

I always used TThread, the object include in the standard lib with Delphi.

 

With that you can do everything. Use "Queue" method to interact with VCL components.

 

Ref: https://docwiki.embarcadero.com/Libraries/Sydney/en/System.Classes.TThread

 

If you have time, explore the use of WaitForxxx with events in Threads ... they can help a lot your works.

 

Of course the other libraries can help to do specific works and can extend the functionality of the Thread.

 

Share this post


Link to post

It sounds rather straightforward. From your description, I don't even see the need for using TThread.

 

Instead, I would

  1. Declare your each of your work items as a Task (from the System.Threading unit)
  2. Put all those tasks in an dictionary, so you have a relationship between your tree view item and the task
  3. Start the tasks
  4. In a timer, check which tasks are finished, so you can tick your checkmark in the treeview

See Parallel Programming Library Tutorials - RAD Studio for more information and examples.

Share this post


Link to post
8 minutes ago, DelphiUdIT said:

Use "Queue" method to interact with VCL components.

 

1 minute ago, Der schöne Günther said:

Declare your each of your work items as a Task (from the System.Threading unit)

OP is on Delphi 2007...

Share this post


Link to post
38 minutes ago, Anders Melander said:

 

OP is on Delphi 2007...

OOps ... sorry I didn't note that ... except "Queue" than he can use "Synchronize" (is not async), the others things should working.

Share this post


Link to post
56 minutes ago, Anders Melander said:

 

OP is on Delphi 2007...

XE6 in the meantime (don't ask :classic_wacko:)

 

But still no System.Threading AFAICS.

Edited by uligerhardt

Share this post


Link to post
25 minutes ago, uligerhardt said:

XE6 in the meantime

Okay, so I would recommend that you simply start with the RTL TThread. Mainly because it appears that you have no prior threading experience (or you probably wouldn't have asked in the first place) and it would be best to learn the basics before trying something more advanced. Threading might seem easy but it's actually really difficult if you don't know and understand the many things that can go wrong.

 

I would also avoid the various 3rd party threading libraries, even though I'm sure they can do some nice things, so you don't introduce external dependencies and get locked in to their way of doing things. Once you know a bit more you can make an educated decision about which way to go.

 

The PPL was introduced in XE7 but I think it took a while for it to become reliable(ish). I stayed clear of all the versions between XE2 and Delphi 10 so I don't have first-hand experience with those versions. These days I seldom use TThread directly. Most of my thread tasks are short lived so they benefit from the TTask thread pool (and TTask is just so much nicer to use).

Share this post


Link to post
3 hours ago, Anders Melander said:

Okay, so I would recommend that you simply start with the RTL TThread. Mainly because it appears that you have no prior threading experience (or you probably wouldn't have asked in the first place) and it would be best to learn the basics before trying something more advanced. Threading might seem easy but it's actually really difficult if you don't know and understand the many things that can go wrong.

 

I would also avoid the various 3rd party threading libraries, even though I'm sure they can do some nice things, so you don't introduce external dependencies and get locked in to their way of doing things. Once you know a bit more you can make an educated decision about which way to go.

 

The PPL was introduced in XE7 but I think it took a while for it to become reliable(ish). I stayed clear of all the versions between XE2 and Delphi 10 so I don't have first-hand experience with those versions. These days I seldom use TThread directly. Most of my thread tasks are short lived so they benefit from the TTask thread pool (and TTask is just so much nicer to use).

I did some threading experiments with TThread but in a more complicated situation and dropped that - I would have had to accept user input in dialogs during the thread.

For my current needs handing a anonymous procedure to the thread should suffice, I think. So I'll try TThread again.

 

Thank you all for answering to my not very well prepared question.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×