问题描述
当我尝试执行一些并行操作时,我收到尝试读取或写入受保护内存"的消息.我正在将 AutoCad 数据库读入内存以进行一些数据挖掘.我可以用一个常规的 for
循环来做到这一点,但不能用一个 Parallel.ForEach
.有什么想法吗?
Parallel.ForEach(_Files, (currentFile) =>{var _File = currentFile;使用(数据库 _Database = 新数据库(假,真)){_Database.ReadDwgFile(_File, FileOpenMode.OpenForReadAndAllShare, false, null);_Database.CloseInput(true);//做东西}});
正如
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
}
});
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
这篇关于“试图读取或写入受保护的内存"并行读取 AutoCad 数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!