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()?
Solved! Go to Solution.
Solved by fenton.webb. Go to Solution.
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, 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.