Loooping through DataSet with threads but locking
-
Hi, I need to have maybe 5 threads running which all use the same DataSet and need to loop through all the rows retrieved but each row must be processed by one thread only (e.g. I don't want row 1 to be processed by thread 1 and thread 3). I can also use a DataReader if that helps, but I need to dow some locking logic I would have thought. Can anybody please help as I've no experience of doing this before? Thank you
-
Hi, I need to have maybe 5 threads running which all use the same DataSet and need to loop through all the rows retrieved but each row must be processed by one thread only (e.g. I don't want row 1 to be processed by thread 1 and thread 3). I can also use a DataReader if that helps, but I need to dow some locking logic I would have thought. Can anybody please help as I've no experience of doing this before? Thank you
Pass each thread a row to process, or a list of rows to process. Lock won't help you much here since it suspends the thread until the lock is released. You would need to check if a thread is (or has) processed that row, which is a different logic altogether.
If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.
-
Pass each thread a row to process, or a list of rows to process. Lock won't help you much here since it suspends the thread until the lock is released. You would need to check if a thread is (or has) processed that row, which is a different logic altogether.
If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.
-
Ok, thanks. So how do check if it has processed or is processing a row which has been used/is being used? Thanks
Yo will have to do that yourself - either by handing the thread only the row(s) you want it to process (my preferred option) or by keeping a list of all rows that have been processed and checking it in your thread. If you go for the second option, you will need to lock the list before your threads access it!
If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.
-
Yo will have to do that yourself - either by handing the thread only the row(s) you want it to process (my preferred option) or by keeping a list of all rows that have been processed and checking it in your thread. If you go for the second option, you will need to lock the list before your threads access it!
If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.