Friday 27 February 2015

Access Violation in ArcObject Multi-threaded Application


I think I have figured it out. The most probable cause of exception in Multithreaded application may be:


When both threads trying to open same featureclass it breaks: coz one of the thread is already in the process of opening it and other tries to do the same, So it gives error like:


"Memory could not be read or write from protected memory"


This is my guess, but what wonders me is that why there is no separation of concern, even if I am opening a different workspace in each thread. May be Arcobjects internally, looks for same address space for any object in database. I have written few lines of code and tried to run it with different threads opening different object classes and this also breaks but

whenver, I deligate few thread to open same featureclass it breaks with the above errors.


Also, not releasing memory is the other cause for such errors as well.


Any suggestions?


Adding some code for more clarification:


private void ReadFeatureClass(string featureclassname)  
{
IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactory();

IPropertySet connectionProperties = new PropertySet();
connectionProperties.SetProperty("SERVER",settings.Server);

connectionProperties.SetProperty("INSTANCE", Settings.Instance);
connectionProperties.SetProperty("USER", settings.User);
connectionProperties.SetProperty("PASSWORD", settings.Password);
connectionProperties.SetProperty("VERSION", settings.Version);

FeatureWorkspace featureWorkspace = workspaceFactory.Open(connectionProperties, 0) as IFeatureWorkspace;

ITable featureClass = featureWorkspace.OpenTable(featureClassName);
}


Above code breaks with the said exception most of the time.


@AndOne, I am using oracle spatial direct connect. Also, I created a new feature class and ran the same code against it, this also fails when threads are increased. There are few differences which I could figure out between these two featureclasses:


Any suggestions?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...