.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

access drawing database from a different thread

6 REPLIES 6
Reply
Message 1 of 7
matus.brlit
1256 Views, 6 Replies

access drawing database from a different thread

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.

6 REPLIES 6
Message 2 of 7

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 -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 7

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

Message 4 of 7

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 -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 7

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 🙂

Message 6 of 7
norman.yuan
in reply to: matus.brlit

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.

 

Message 7 of 7

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 -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost