4

I am getting "Attempted to Read or write protected memory" when I try to perform some parallel operations. I am reading AutoCad Databases into to memory to do some data mining. I can do this with a regular for loop but not with a Parallel.ForEach. Any ideas?

Parallel.ForEach(_Files, (currentFile) =>
{
    var _File = currentFile;
    using (Database _Database = new Database(false, true))
    {
        _Database.ReadDwgFile(_File, FileOpenMode.OpenForReadAndAllShare, false, null);           
        _Database.CloseInput(true);
        // Do Stuff
    }
});
cmoha
  • 73
  • 1
  • 2
  • 10
James Morris
  • 353
  • 5
  • 20

2 Answers2

6

As mentioned by Miiir, AutoCAD does not support multi-threading.

The workaround could be with AutoCAD Console (accoreconsole.exe). If you have an external app (.exe), use it to call several instances of the console, where you can NETLOAD a .NET plugin that will do your data mining. As each console instance is a separate app, there is no multi-thread.

I did some testing with AutoCAD Console on a 8-core machine. As you can see, the overall process takes less time (when compared to running in sequence). Check this PDF I wrote: Using .NET Programming to Create New Possibilities with the AutoCAD® Core Console

enter image description here

Community
  • 1
  • 1
Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
  • Thanks for posting the PDF. I tried to find the class outline at http://au.autodesk.com/au-online/overview but that site is completely useless for finding anything from the past. Try searching for "cp3338" or "core console". – CAD bloke Nov 24 '15 at 20:49
2

AutoCAD does not support multi-threading or parallel processes.

Miiir
  • 731
  • 1
  • 9
  • 12