I have a challenge here, and it's giving me a headache to find a solution.
I have a List of something, and I execute the Parallel.ForEach based on it:
List<Customer> customers = GetNotProcessedCostumer();
Parallel.ForEach(customers, new ParallelOptions {MaxDegreeOfParallelism = 2},
cust=>
{
ExecuteSomething(cust);
});
The problem here is that I need to call GetNotProcessedCostumer again to check if new not processed items are available on database, while this parallel is still running.
Call the method again is OK, but, how can I insert new items in the List that the parallel is already using ?
In others words, the List<Customer> is alive, and I need to insert items all the time on it, and try to use the available threads in the existing Parallel. Take a look:
List<Customer> customers = GetNotProcessCustomer // get not processed customers from database
Parallel.ForEach(customers) // ...... Start the parallel ...
customer.Add(GetNotProcessCustomer()) // Read database again..
"Hey Parallel, do you have any thread available ?" If yes, use it.
I can accept others approaches and ideas, like Threads, ThreadPool.........
Could someone help me please?