Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The possibility that comes immediately to mind is to use a broadcast datagram that contains a close message and the process id of the one that you want closed. Each of the console processes listens for broadcast datagrams on a common port. When the program receives a datagram, it parses the data, checks the passed process id against its own process id, and if they match, the program initiates a clean shutdown.</p> <p>This assumes, of course, that you have created a way for the program to shut itself down cleanly.</p> <p>Broadcast datagrams aren't guaranteed to be received, of course, but my experience has been that they're reliable on a single system. If you run into a problem, you could have your main program send the datagram, wait some period of time to see if the program has shut down, and if not then send the datagram again.</p> <p>Another possibility is to create a named <code>EventWaitHandle</code> for each process that you start, passing the name of that event to the console application on the command line. The console program could then have a thread that does a <code>WaitOne</code> on that event. When the event is set, the program initiates a clean shutdown. This is more reliable than the broadcast datagram. Sure, it uses another handle per process, but that won't be a problem unless you have thousands of processes.</p> <p>See <a href="https://stackoverflow.com/questions/480430/send-message-from-one-running-console-app-to-another/480707#480707">Send message from one running console app to another</a> for an example of using a named wait handle to communicate between processes.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload