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.
Solved! Go to Solution.
Solved by conormccartney3897. Go to Solution.
Solved by Alfred.NESWADBA. Go to Solution.
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 -
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.
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.
Hi,
thank you for your feedback, gives me sime free minutes now 😉
- alfred -