.NET

Reply
Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 1 of 3 (344 Views)

Access drawing from new thread

344 Views, 2 Replies
02-17-2012 12:07 AM

Hi,

 

I found out, that you can't read AcApp.DocumentManager.MdiActiveDocument from a new thread, so I was passing the reference to the document to every method that needed to use it

But then I found out, that HostApplicationServices.WorkingDatabase allows me to access the database from a new thread.

So I'm wondering, is there any other difference, whether I access the database using AcApp.DocumentManager.MdiActiveDocument.Database or HostApplicationServices.WorkingDatabase ?

 

And is there some way for thread-sefe access to the active document?

Board Manager
StephenPreston
Posts: 368
Registered: ‎05-22-2006
Message 2 of 3 (315 Views)

Re: Access drawing from new thread

02-18-2012 09:17 AM in reply to: matus.brlit

Hi Matus,

 

AutoCAD APIs are not multithreaded safe, so you should only access the AutoCAD APIs from your main thread. This is documented in the ObjectARX helpfiles. If you want to process data on another thread, its best to extract what you need on your main thread, send it to your worker thread, and then send the result back to the main thread if you need to send something back to AutoCAD.

 

But to answer your question on Databases, HostApplicationServices.WorkingDatabase and MdiActiveDocument.Database will (in general) return the same Database.

 

Cheers,

 

Stephen

Cheers,

Stephen Preston
Autodesk Developer Network
Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 3 of 3 (290 Views)

Re: Access drawing from new thread

02-19-2012 11:11 PM in reply to: StephenPreston

Thanks for the clarification on databases.

 

But can you also explain why HostApplicationServices.WorkingDatabase is threadsafe? At least it works for me.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community