Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Attempted to Read or write protected memory" error reading AutoCad databases in parallel

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
    }
});
like image 844
James Morris Avatar asked Mar 14 '23 03:03

James Morris


1 Answers

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

like image 156
Augusto Goncalves Avatar answered Apr 06 '23 19:04

Augusto Goncalves