How do I capture an application close event of an application hosting my vb.net class libary tool?

StackOverflow https://stackoverflow.com/questions/10389102

  •  04-06-2021
  •  | 
  •  

Question

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?

Was it helpful?

Solution

There is an event handler for the currently opened document in ArcMap. Have a look here:

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/BeforeCloseDocument_Event/000v000000pn000000/

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).

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top