I will love the person to death that can give me a solution for this issue I'm faced with. I have been at this since 11 am (it's now 9:11 PM my time) and have made little, to no progress, despite scouring every web site I can muster to find. I have a foreach loop that pulls from a client, studies it, and then makes db changes. This has been working out for quite sometime as the lists have always been very small, which leads me into the issue; the problem in itself, is very simple.
The problem is that the bigger that list gets, the longer the process takes. So if the list contains 8500 complex objects, the list takes an hour to complete. So I thought to myself, lets make it use the parallel and cut that time down as much as I can. Thus, the torture began.
TL;DR:
I have a data table, which by nature is read thread safe but not write thread safe. So I thought well no big deal I'll just lock the table rows when I need to add a new row and I'll be set. The problem is, the only way I can get it to work is if I put the entire body of everything into a lock call, which takes longer then the non-parallel version does as so:
It will work in amazing time about 0.455 seconds. But if I try to modify productDR it fails hard. I've tried many different locations of locks and different objects to lock (locking a generic object, locking the data row item array, the whole data table, etc). Unless I put it all in one big lock body (which defeats the purpose), it fails. Surley there has to be some way to do this? I don't care what order anything gets processed or added. I just want it to get done in the most efficient way possible.
Question
sathenzar
I will love the person to death that can give me a solution for this issue I'm faced with. I have been at this since 11 am (it's now 9:11 PM my time) and have made little, to no progress, despite scouring every web site I can muster to find. I have a foreach loop that pulls from a client, studies it, and then makes db changes. This has been working out for quite sometime as the lists have always been very small, which leads me into the issue; the problem in itself, is very simple.
The problem is that the bigger that list gets, the longer the process takes. So if the list contains 8500 complex objects, the list takes an hour to complete. So I thought to myself, lets make it use the parallel and cut that time down as much as I can. Thus, the torture began.
TL;DR:
I have a data table, which by nature is read thread safe but not write thread safe. So I thought well no big deal I'll just lock the table rows when I need to add a new row and I'll be set. The problem is, the only way I can get it to work is if I put the entire body of everything into a lock call, which takes longer then the non-parallel version does as so:
It cut off the rest of my post :( but it's got to be b/c the whole lock statement is dragging down the performance. Now if I use this method:
It will work in amazing time about 0.455 seconds. But if I try to modify productDR it fails hard. I've tried many different locations of locks and different objects to lock (locking a generic object, locking the data row item array, the whole data table, etc). Unless I put it all in one big lock body (which defeats the purpose), it fails. Surley there has to be some way to do this? I don't care what order anything gets processed or added. I just want it to get done in the most efficient way possible.
Link to comment
Share on other sites
31 answers to this question
Recommended Posts