[quote=116984:@Walter Sander]Maybe I could mix both solutions:
Queue + cap of X parallel jobs.
In a later stage, I could even increase/decrease the X value to make use of available system resources.
[/quote]
The word “parallel” does not quite reflect what threads are. In effect, threads execute in the background but are not truly parallel, as they use the same processor core. The only way to achieve true parallel processing would be to spawn subprocesses. But this would be a lot more involved.
Back to the option to mix queues and several thread. Yes, of course, you can mix. The issue you will face is the need to coordinate tasks. Let us say a task is made of 3 steps : get parameters/calculate 3 seconds/hand the result to a timer to update the listbox.
In the one queue+one thread model, each time the user clicks, a task is put on the pile with the parameters. Here starts a problem : what are the parameters stored ? If your application uses for instance TextFields with numbers as base for the calculus, it probably would not make sense to launch the same task with the same parameters twice in a raw. So you should probably verify that parameters are not the same before piling a new task.
Then, imagine the (fast) user changes the data and clicks at the rate of 1 per second. With one thread, while the first task is still executing, the user will have queued 3 new ones. So if the task manager (most probably in a timer) waits for each task to complete before sending a new one, that accounts for a total of 4 tasks x 3 seconds = 12 seconds total.
In order to have a faster response time, it makes sense to use 4 identical threads, each managing a task, so the result may be ready in 3 seconds after the click.
This looks like what you wanted to do initially, but using a queue and a task manager will enable using a finite number of threads and allocate tasks to each according to availability. So if the crazy user keeps inputing new data, your program will not miss anything and keep being responsive.
Now, on the other end of the tunnel, you need to coordinate things as well. If you have only one thread, it is simple enough : a timer can check if the thread has ended, and if so, collect the result and update the listbox. But if you have several threads running from your temperamental user, then you need to monitor all of them. And place the result in good order in the listbox. If each task takes a fixed time to complete, that is fine. If that time is variable, you need to know the order in which tasks where input to update the listbox in the same order.
In fact, there are no theoretical obstacles to the number of threads, but in practice, the queue and a task manager is the only way to insure a smooth business. And also, your user interface must be conceived to update gracefully without major disruption to the user.