Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

custom .NET app crashses in new drawing

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
conormccartney3897
398 Views, 4 Replies

custom .NET app crashses in new drawing

So I'm novice at .NET and have written an app that loads a windows form, inserts several blocks depending on button click, rotates them then counts them up. it seems to be working fine. The occasional problem is when i start or open up a different drawing, running the app (always running from command line) will cause autocad to crash. Now if i go back in and open up the drawing it crashed on, it works fine and then may work on a second drawing fine. So questions, has anyone else experienced this? Is this due to the app being still resident after the first run? Am i missing some code when i hit the exit button to clear it out? (im guessing here) Anyways the code is attached for those that would like to look at it.  Running C3D 2011 Update 2, on Win 7 64 bit.
4 REPLIES 4
Message 2 of 5

Hi,

 

Your problem is (at least one of your problems) the incorrect usage of Using/End Using in combination with .Dispose

If you are working with Using/End Using it is wrong to do a .Dispose of the object in the mid of the Using/End Using region.

 

Look e.g. to that part of code (I deleted the lines not necessary to show the problem)

 

Using tr As Transaction = db.TransactionManager.StartTransaction()
   '''commented out
   If Not bt.Has(BlockName) Then
      Dim origin As New Point3d(0, 0, 0)
      Dim filename As String = "C:\xxx\Blocks\StallCount.dwg"
      ed.WriteMessage(vbLf & BlockName & " block not found, now inserting!")
      Using dbdwg As New Database(False, True)
         '''commented out
         dbdwg.Dispose()
      End Using
   End If
   tr.Dispose()
   db.Clayer = Lt("C-VPRT")
End Using

 

I have marked with colors the positions you have to think about (to correct). 😉

 

I did not run your code, so there may be more errors, at least this one is able to crash your AutoCAD.

 

- alfred -

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

hrmm okay i see what your saying. i removed those two .dispose elements but did not fix teh problem. with those removed i tested four drawings then crash, restarted cad  then crashed on second drawing.

Message 4 of 5

oookay after playing with the code some more i think i solved it, now going on ten coninous drawings started or opened through various methods, no crashes.

This was the bugger in question:

 

Blockname = Nothing

 

wierd right? i was trying to clear the variable before my next button click, this along with the tr.dipose that i got rid of seems to have fixed it. (Also re-wrote the layer checking section)

 

Here's the new code for anyone who wants to take a look.

Message 5 of 5

Hi,

 

thank you for your feedback, gives me sime free minutes now 😉

 

- 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  

Rail Community


 

Autodesk Design & Make Report