Page 1 of 1
[SOLVED] Thread with multiple processing loops
Posted: Sun May 25, 2025 5:10 pm
by boddhi
Hello,
Note: The use and programming of threads is still a bit of a mystery to me. I'm gradually trying to understand and learn how to use them

.
I have a question about the best way to proceed in the following case:
A first loop retrieves data by sending an indeterminate number of HTTP requests. Once this is done, another loop performs some processing on the data.
My question is whether it's better to manage both loops within a single thread or to launch two threads for each of them (Thread → Loop 1 → End of thread → New thread → Loop 2 → End of thread) ?
Thanks for your answers.
Re: Thread with multiple processing loops
Posted: Sun May 25, 2025 5:19 pm
by mk-soft
Since this is performed in a sequence in a sequence, a single thread is sufficient
Re: Thread with multiple processing loops
Posted: Sun May 25, 2025 10:20 pm
by boddhi
mk-soft wrote:
Since this is performed in a sequence in a sequence, a single thread is sufficient
Thanks for your reply
Another (noob's) question: I understand that you have to use a memory address (to a string or a structure) when you want to pass non-numeric parameters through a PostEvent.
I see in your example #5 that you use it to feed a ListView.
In my code, I feed my gadgets designed to receive text (TextGadget, StringGadget, ListIcon, etc.) with dedicated commands (SetGadgetText, ...) directly from the threaded procedure. This works well.
Is this not recommended as I do, and if so, why or both methods are possible ?
Thanks in adavnce.
Re: Thread with multiple processing loops
Posted: Mon May 26, 2025 6:10 pm
by mk-soft
boddhi wrote: Sun May 25, 2025 10:20 pm
Another (noob's) question: I understand that you have to use a memory address (to a string or a structure) when you want to pass non-numeric parameters through a PostEvent.
I see in your example #5 that you use it to feed a ListView.
In my code, I feed my gadgets designed to receive text (TextGadget, StringGadget, ListIcon, etc.) with dedicated commands (SetGadgetText, ...) directly from the threaded procedure. This works well.
Is this not recommended as I do, and if so, why or both methods are possible ?
With Windows it works in most cases. But as soon as you switch to Linux or macOS, it crashes.
Re: Thread with multiple processing loops
Posted: Mon May 26, 2025 9:54 pm
by boddhi
mk-soft wrote:
With Windows it works in most cases. But as soon as you switch to Linux or macOS, it crashes.
Thanks a lot for all these explanations.
However, I must admit that I don't always understand why some actions on gadgets, depending on where they are placed in the threaded procedure, work or don't work. I find other ways of getting things done.
Maybe it's due to the timeout used with WaitThread...
Re: [SOLVED] Thread with multiple processing loops
Posted: Tue May 27, 2025 3:45 pm
by jacdelad
Most actions, if not all, performed on gadgets shouldn't be done within a thread, but outside of it, triggered by a message. However, there's a mk-spft-code floating around in the Tips & Tricks sub forum, which addresses this especially for threads. Worth a look.
Also, without code it's hard to say why your code does not always work...
Re: [SOLVED] Thread with multiple processing loops
Posted: Wed May 28, 2025 7:26 pm
by boddhi
Hello jacdelad
jacdelad wrote:
there's a mk-spft-code floating around in the Tips & Tricks sub forum, which addresses this especially for threads. Worth a look.
Probably the one I was referring to when I mentioned example #5

(

ouupss, I seem to have forgotten to mention it in this post:
it's here).
jacdelad wrote:
Also, without code it's hard to say why your code does not always work...
I know, I know...

but, even if it's related to one of my codes, my questions were of a general nature, to better understand how threads work. Given the length of the code and the many procedures called, it might have been complicated to isolate or reproduce the problem I was having.
I don't claim to have understood everything about threads yet, but I followed some mksoft's advices and was able to get the result I wanted without any crashes

.