Ok, I understand that it's a .NET app your trying to close.
I'm unclear as to whether issuing a WM_QUIT message via the SendMessage Win32 API is the same as using Process.Exit
Process.Exit does not exist. Do you mean Environment.Exit or Process.Kill?
They are all very different:
WM_QUIT informs the app to quit, but it requires a message loop and does not guarantee that the app will listen.
Process.Kill() method uses an unmanaged call into kernel32 to stop the application. This kills the threads and background threads
of the application. It does not close down the application gracefully.
Environment.Exit is the same as using the unmanaged ExitProcess function which gracefully shuts down an application.
If there is a message loop running on the main thread of your application, all 3 solutions will close your application if you are
not handling the WM_QUIT message yourself.
the reason using Process.Exit doesn't work is because my app doesn't startup from a form. It starts from a class and after doing
some startup tasks it calls application.run(mainForm),
The message loop must be started on the thread of the application's Main method. As long as you are not calling Application.Run on
a different thread, all 3 solutions above will close your app.
also this form is a set to a window type of "tool" (uses SendMessage function to do this so the window is completely hidden while
it runs in the tray area).
Just set the form's "ShowInTaskbar" property to "false" and override SetVisibleCore() with the following implementation:
public override void SetVisibleCore(bool Show)
{
if (Show)
return;
base.SetVisibleCore(Show);
}
With the code above, your form will never be visible.
I was also wondering if there was a way for me to call the application's close method but I don't if that's doable. You mention
that "if it's COM visible" I could access it, however I'm assuing it is not since it's a .NET app.
To call a method across process boundaries, you can use Remoting. That's a whole 'nother topic, although it's not too difficult to
implement
COM would work too event though it's a .NET app, but it's not nessecary with the Remoting framework which keeps things "managed".
There are a few things you can do to close your app from another process. If Envirnoment.Exit() is not working properly in your
situation, it's likely because the app is not tearing down nicely. Make sure you don't have any code in the Close override that
could cause a problem, just in case.
If the WM_QUIT message isn't doing the trick, I'd assume that your message loop is not on the main thread. I could be wrong about
this requirement, however.
GL