“试图读取或写入受保护的内存"并行读取 AutoCad 数据库时出错 [英] "Attempted to Read or write protected memory" error reading AutoCad databases in parallel

查看:37
本文介绍了“试图读取或写入受保护的内存"并行读取 AutoCad 数据库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试执行一些并行操作时,我收到尝试读取或写入受保护内存"的消息.我正在将 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 数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆