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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With