Calling CloseMainWindow will essentially send a Close request message to the running application, whereby it is up to that application to handle the event--This is the most graceful approach because it allows the application to perform it's normal process termination. It should be followed by a call to Close to perform resource cleanup.
// Close process by sending a close message to its main window.
myProcess.CloseMainWindow();
// Free resources associated with process.
myProcess.Close();
Calling Kill will terminate the process, but at the risk of losing any unsaved data or even corrupting data if in progress of writing. I believe that allocated resources my also not be freed. You can call Kill if the above recommended close fails.
As far as the MainWindowHandle, I'm not sure why are you are doing that.
Also, take a look at this article: Make Your Application Shutdown Aware . If you implement graceful handling of a close request in your process, you should have not problems when you want to shut it down from your service.
Cheers!