Retnuoc
Retnuoc

Reputation: 45

How to gracefully end a process without using CloseMainWindow

Is there a way to gracefully end a process without using Process.CloseMainWindow()?

I have a bunch of processes in a list which I want to end. The process should be ended without Process.Kill() to make sure they clean up and end their child processes as well. I tried CloseMainWindow, but unfortunately it will make my process pop up a messagebox with "Do you really want to end the programm?"[Yes][No] which I want to avoid.

The processes have a message handler for WM_QUERYENDSESSION but when I tried to send a WM_QUERYENDSESSION message to the process, it didn't react on it. It just reacts on WM_QUIT, but the behaviour looks like the one when calling Process.Kill().

I couldn't find a proper solution yet. Hopefully I didn't overlooked things in here...

Upvotes: 1

Views: 927

Answers (2)

Retnuoc
Retnuoc

Reputation: 45

Well after a while I admit that there seems to be no real answer to this explicit problem.

Since I got control of both parts I just removed the "Do you really want to quit?" pop up like IInspectable assumed and send a message via the opened pipe to the child process like Sefe assumed.

Upvotes: -1

Anders
Anders

Reputation: 101756

Sending the WM_CLOSE message is pretty much the same as clicking the close button on a window. Applications will be able to block this request or put up a "Save your changes" confirmation dialog.

Anything beyond this and you risk loosing data. WM_QUIT is not something you should be sending.

WM_QUERYENDSESSION is a query, you would send that first and then WM_ENDSESSION but not all applications will handle these messages.

Win32 does not have a main-window property, it is a .NET concept.

Another thing you should look into is the restart manager feature if you plan on restarting these applications again when you are done with whatever you are doing.

Upvotes: 1

Related Questions