Yeah I know - one of the following lines will do this usually:
AppDomain.CurrentDomain.ProcessExit += OnApplicationExit;
Application.ApplicationExit += OnApplicationExit;
void OnApplicationExit(object sender, EventArgs eventArgs) { ... }
But what when one don't use any forms in a WinForms application? To make it a hidden windows application - which is not a service. Both of the above examples don't work for me.
This is how I start my WinForms app. As you can see I don't pass any form to the Run
method
public static void Main()
{
InitMyApp();
// Here I tried to subscribe to the above shown events => didn't work.
Application.Run();
}