Hi,
I'm experimenting with treadsafe progressbar, that would allow me to stop the process.
but for some reason, on this line
Dim _db As Database = AcApp.DocumentManager.MdiActiveDocument.Database
AutoCAD crashes with fatal error
This runs on the new thread, so i suppose it has something to do with it, but i have no clue, why this should be a problem.
Hi,
just to verify, if you use this statement in the main-thread it does not crash?
If so, have you tried to initialize the variable _db in you master-thread and transfer it as parameter to your slave-thread(s)?
- alfred -
yes, in one thread, it works all just fine
i tried your advice, i passed the database to all methods running on the new thread, it worked, but then it crashed again on this code:
Dim layer As New LayerTableRecord layer.Name = meno
which is really strange, as it is just creating new layer, not changing anything that could be protected from cross-thread access
Hi,
what AutoCAD-version/what Framework-version and what technique do you use for multithreading (normal System.Threading or >>>Async CTP<<< or the System.Threading.Parallel-class?
If you can upload a short sample project I can look behind it (VS2010).
For me the functionality of using multithreading with AutoCAD makes sense with Framework 4 (and so AutoCAD 2012) using the parallel-class. It's really easy to use, no conflicts any more with transfering parameters/pointers to subthreads/having to do a lot of delegates and callbacks/... and easier debugging too!
In other words this is multithreading for dummies (for me!) 😉
- alfred -
I'm using AutoCAD 2012, VS 2008 and .NET 3.5
i use classic System.Threading where i start a new thread using ParameterizedThreadStart Delegate
i never heart of the Parallel class, but it looks simple and clear
unfortunately, i can't provide any short sample, because the project is quite big and most of the code consists of my methods
anyway, thanks for the poke, i hope it will be in the right direction 🙂
Yes, it is possible to do multi-threading in Acad .NET development; but no, you cannot do multi-threading when accessing drawing database with ObjectARX (C++ or .NET API). Precisely, what you did (obtaining drawing database in one thread and pass it to other thread to run some processes) is not supported.
That is, you only access drawing database and its members in the main AutoCAD execution thread. You can run non-ObjectARX tasks in other threads, such as calling external services or to access external data sources...which run in different threads and do not touch drawing database.
Hi,
>> Precisely, what you did (obtaining drawing database in one thread and
>> pass it to other thread to run some processes) is not supported.
Well lets be more specific, sorting new entities into the same database is not possible from different threads, but what part from the following statement from matus.brlit
Dim layer As New LayerTableRecord
does touch the current database (or any other db). Every creation of geometry in memory could be done in multiple threads, placing them into a BlockTableRecord has to be done in the main-thread.
- alfred -