Use another event to access your own Exit button. In your own Exit event handler, execute additional logic or set some state variable and then call the method of closing a regular application.
Send some examples of how your events are connected, and I will give a more specific example. In general, it would look something like this:
private void btnMyExit_Click(object sender, EventArgs e)
{
doCustomExitWork();
}
public static void OnAppExit(object sender, EventArgs e)
{
doCustomExitWork();
}
private void doCustomExitWork()
{
}
source
share