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

和自甴很熟 提交于 2019-12-10 17:20:51

问题


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
    }
});

回答1:


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




回答2:


AutoCAD does not support multi-threading or parallel processes.



来源:https://stackoverflow.com/questions/33765794/attempted-to-read-or-write-protected-memory-error-reading-autocad-databases-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!