Click here to Skip to main content
15,909,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to dequeue the elements of a collection one by one then store their values in a MYSQL database.
When the first element is dequeued I want to start a thread to update the database, then when the second element is dequeued I want to start another thread.
When the first thread finishes execution, I want to reuse it handle the third element of in the queue. Then, after the second thread finishes execution, I want to reuse it to handle the fourth element in the queue. I want to continue this way until all the elements in the queue are processed.
These all process handle the another thread at 1ms.
Does anyone know how to process a collection one by one using two threads?dequeue the element one by one then stored this value to the MYSQL database.
when first element dequeue then start another thread to update the database,
then second element dequeue then start another thread , when first finish execution handle the third element of the queue then second handle the fourth element & so on..
these all process handle the another thread at 1ms.
if any one known to how to start the one by one thread then tell me the solution.
thanks in advance.
Posted
Updated 24-May-11 20:18pm
v2

1 solution

Dequeue your Queue<T> or ConcurrentQueue<T> and use ThreadPool.QueueUserWorkItem[^] to create threads that handles MySql INSERT statements.

But this can make a high load on MySql and connection creations. Perhaps it is better to do chunks of inserts ?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900