.NET

.NET

Reply
Valued Contributor
bjhuffine
Posts: 76
Registered: ‎08-13-2008
Message 1 of 3 (356 Views)
Accepted Solution

Catch AutoCAD on Shutdown after Fatal Exception?

356 Views, 2 Replies
07-24-2013 12:04 PM

I have this application I'm working on where I can't just start it in a try{}catch{} in a CommandMethod.  In fact, the best way (too long a story for this post) I could initialize some objects to manage WCF callbacks in the main application thread was via a combination use of the IExtensionApplication's Initialize() and Application.Idle event.  That part works wonderful, but with an unfortunate side-effect.  If AutoCAD crashes due to some fatal exception, I'm unable to report back to the WCF service the change in AutoCAD state. 

 

So, basically (without going into a lot of detail) the question is this:

 

How do I capture an AutoCAD crash event so that I can finalize closing of specific resources when initializing an assembly via the IExtensionApplication's Initialize()?

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 3 (317 Views)

Re: Catch AutoCAD on Shutdown after Fatal Exception?

07-25-2013 03:09 PM in reply to: bjhuffine

your comment about CommandMethod() not working for your WCF initialization could
be solved by using the Session command method attribute parameter. I don't
recommend setting up initialization code in OnIdle etc because OnIdle can occur for lots of different *unsafe* contexts.
 
To capture a crashing AutoCAD from .NET is not going to be easy at all. We use a C++ method
for capturing the exceptions and then overwrite the return address to stop people from overriding it. Here's the explanation and solution to the problem in C++ http://adndevblog.typepad.com/autocad/2013/02/overriding-the-setunhandledexceptionfilter-for-autocad... 
 
The simplest way to make this work is to create manager exe that controls the AutoCAD processes that you start. Your AutoCAD addin should register the WCF job, as should the manager exe, if the manager exe detects a crashed system or the WCF job is taking too long to process then the manager exe kills AutoCAD and then restarts everything.





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Valued Contributor
bjhuffine
Posts: 76
Registered: ‎08-13-2008
Message 3 of 3 (303 Views)

Re: Catch AutoCAD on Shutdown after Fatal Exception?

07-26-2013 05:30 AM in reply to: fenton.webb

Fenton, as always your insight is much appreciated!  Sorry about this plus the case.  I didn't realized you guys watched these forums this closely and I figured my original "no answer" here probably meant it was a little too out of the ordinary for others and probably more appropriate for you guys directly.  I'm still trying to look at our options around your suggestion with the least impact to performance, but please let us know if there's a reasonable way in the future for us to be able to inject our management code without impacting your reporting process.  At least if I may suggest such a feature for the AutoCAD .Net API.  In other words a safe invocation of a delegate we provide through the API while still allowing all the AutoCAD "crash" processes to keep running?  Again, just a suggestion.  Right now the work around involves a lot of overhead and performance considerations whereas a nice little place to inject some "crash-management" code would've prevented a lot of that.

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 or visit the Installation and Licensing Forum to get help installing your software.