Is there an Unload event, or any event, notification, message, mechanism, or hook, that i can use to be notified before the \"default\" applicatio
i forgot to cross post my own answer from my other slight variation of this question. Ultimately, the answer came from an answer by M.A. Hanin.
There is no DomainUnload, but there is a ProcessExit:
class Contoso
{
//constructor
public Contoso()
{
//...
//Catch domain shutdown (Hack: frantically look for things we can catch)
if (AppDomain.CurrentDomain.IsDefaultAppDomain())
AppDomain.CurrentDomain.ProcessExit += MyTerminationHandler;
else
AppDomain.CurrentDomain.DomainUnload += MyTerminationHandler;
}
private void MyTerminationHandler(object sender, EventArgs e)
{
//The domain is dying. Serialize out our values
this.Dispose();
}
...
}
Note: Any code is released into the public domain. No attribution required.
AppDomain.CurrentDomain.DomainUnload +=
(object sender, EventArgs e) => { /*do stuff*/ };