Calling document properties result in crash without thread.sleep

Calling document properties result in crash without thread.sleep

Cadkunde.nl
Collaborator Collaborator
658 Views
1 Reply
Message 1 of 2

Calling document properties result in crash without thread.sleep

Cadkunde.nl
Collaborator
Collaborator

Hello,

 

I programmed a lot in Inventor, but Autocad is new to me.

I'm using Visual Studio Community 2019.

Autocad 2020.

.NET Framework 4.7.2

And added the following references to my project:

AcCui

acdbmgd

acmgd

Autodesk.AutoCAD.Interop

Autodesk.AutoCAD.Interop.Common

 

I made a simple form1 with a button1, when pressing the button, AutoCAD opens a drawing and gives the name of the drawing in a msgbox.

 

I have a question about this piece of code:


Dim oApp As AcadApplication = StartAcad()

oApp.Documents.Open("C:\Temp\aaa.DWG")
Dim oDoc As AcadDocument = oApp.ActiveDocument

msgbox(oDoc.fullname)

If I run this, it crashes on msgbox(oDoc.fullname).

After 2 hours of frustration, I learned that I have to add this:

 

System.Threading.Thread.Sleep(5000)

Before I can call any property from drawing.

 

I programmed a lot in Inventor, and Autocad is new to me. I wouldnt have to add this thread sleep in Inventor between documents.

Maybe there is a better way? Can someone give me insight on what is happening. I don't like to add thread.sleep unless there is no alternative.

 

 

Thanks in advance, Arnold

0 Likes
659 Views
1 Reply
Reply (1)
Message 2 of 2

dlanorh
Advisor
Advisor
You should post this in the ".NET" Forum, Not the Autolisp Forum.

I am not one of the robots you're looking for

0 Likes