I would like to know if there is an existent framework which can manage some “tasks”.
I’m aware of Task Parallelism, but (correct me if I’m wrong) I don’t think it fits my needs (mostly because it works on a finished list of tasks).
The base of my needs is that I want to give to X threads some work to do.
But:
- Every task can generate create new tasks to be executed in the future(can be 0 task like it can be 100 tasks
- If my task list is empty, I would like that my non-working thread wait that all thread have finished their task, maybe I’ve one last thread running, which will generate 50 new tasks that other 3 threads can handle.
Do you know something which can helps me? Or should I have to manage everything by hands?
TPL would work by the sound of it. You can create subtasks, and you can use WaitAll to make sure all tasks are completed.
This way you don’t have to worry about thread management, either.
Without knowing much more about your code, it seems like it could be something like this pseudocode:
UPDATE:
I also forgot that the subtasks need to be marked at inner tasks or else the outer task will not wait. Here is an MSDN on nested tasks and how to work with them. But, in a nutshell, when you create a nested task you have to mark it as attached to the parent task.