I have a set of tools that I've built as a class library that is hosted/referenced within a main application (ESRI's ArcMap). I'd like to manage the case where a user may pull the pin on the main application while they have unsaved/unmanaged edits pending. I tried handling the Application.ThreadExit event w/ no success. Is there a best practice for accessing the closure of a hosting application in .Net? Is this even possible?
-
2This sounds like something which really should be implemented in the application and not in the class library. As long as your class library provides methods to get the state of unfinished business it should be the main application's responsibility to call them and sort out with the user what it should do with unsaved work, etc. Why do you want to do this in the class library?– J...Commented Apr 30, 2012 at 19:25
2 Answers
There is an event handler for the currently opened document in ArcMap. Have a look here:
You can listen to the BeforeCloseDocument_Event
and develop some logic to handle the case of a closing document (the document is closed when the application is closed).
Since a typical WinForms application doesn't close until the main form is closed, you could have the class library handle the host application's main form FormClosing event. To prevent the application from closing, you would set the FormClosingEventArgs object's "Cancel" property to true.