Calling document properties result in crash without thread.sleep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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