Select to view content in your preferred language

FeatureCursor cannot open any more tables in parallel loop

3647
2
09-28-2013 01:27 AM
juan_marvinwirjomartono
Occasional Contributor
Hi all,

I am using VB 2010 to make ArcGIS 10.0 Add-Ins. I always use:

newFeatCursor = Nothing
GC.Collect()


or

System.Runtime.InteropServices.Marshal.ReleaseComObject(newFeatCursor)
GC.Collect()


everytime I use featureCursor to insert features, or others. That piece of code keeps me away from an error that states: "Cannot open any more tables."

Now I have hundred thousands of features to insert. When I use normal loop ( for loop) it works perfectly. Then I want to change those calculations followed by the feature insertion paralleled. I use Parallel.For in VB 2010. And the problem comes when the error: "Cannot open any more tables." keeps coming and coming even though I use:

newFeatCursor = Nothing
GC.Collect()


or

System.Runtime.InteropServices.Marshal.ReleaseComObject(newFeatCursor)
GC.Collect()
.

Any help to make the feature insertion in parallel processing successful will be much appreciated.


Thank you.
0 Kudos
2 Replies
DubravkoAntonic
Occasional Contributor
Im not the expert to tell for sure but it seems to me that your problem is because ArcObjects are based on STA - Single threaded Appartment architerture.
0 Kudos
JohnStephens
Regular Contributor
Yeah you can't essentially edit a table in two different processes at the same time.  It requires an exclusive lock to do that.

Also, I've found that instead of setting the feature cursor to null, something like this is much better:

using (ComReleaser cr = new ComReleaser())
{
   IFeatureCursor updateCursor = featureClass.Update(queryFilter, false);
   cr.ManageLifetime(updateCursor);
   // Do stuff
}
GC.Collect();