Assuming that you are talking about the window close of your own application this can be done by:
Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
But if you are talking about any other appllication running in OS then perhaps u can use some method of following class to monitor the required windows is being opened or closed (as that will start or stop the related process too)
System.Diagnostics.Process