uligerhardt 18 Posted October 30 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
Lajos Juhász 293 Posted October 30 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
DelphiUdIT 178 Posted October 30 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
Der schöne Günther 316 Posted October 30 It sounds rather straightforward. From your description, I don't even see the need for using TThread. Instead, I would Declare your each of your work items as a Task (from the System.Threading unit) Put all those tasks in an dictionary, so you have a relationship between your tree view item and the task Start the tasks 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
Anders Melander 1795 Posted October 30 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
DelphiUdIT 178 Posted October 30 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
uligerhardt 18 Posted October 30 (edited) 56 minutes ago, Anders Melander said: OP is on Delphi 2007... XE6 in the meantime (don't ask ) But still no System.Threading AFAICS. Edited October 30 by uligerhardt Share this post Link to post
Anders Melander 1795 Posted October 30 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
uligerhardt 18 Posted October 30 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