问题
I have a windows form application running on a server. Now I need to have multiple instances of the same application running at the same time. Each instance will connect to a different database. During the application startup I change the title so I can identify which DB is connecting to, but I'd like to change the name in the Task Manager also. This because I have another application that act as a supervisor, killing and starting the process as needed. I have to find a way to clearly identify the process to kill.
回答1:
Have your supervisor create a temporary copy of the executable, including your identifying information, and start that... so that Task Manager will look like
My process - database 1.exe
My process - database 2.exe
et cetera
回答2:
If the Supervisor program is the one starting the processes, you will have full control over these child processes. You can easily kill/start them as you need. Use Process as needed.
using System.Diagnostics;
Process p1 = new Process();
Process p2 = new Process();
Process p3 = new Process();
p1.StartInfo.FileName = "notepad.exe";
p2.StartInfo.FileName = "notepad.exe";
p3.StartInfo.FileName = "notepad.exe";
//start the procs
p1.Start();
p2.Start();
p3.Start();
//kill the procs
p1.Kill();
p2.Kill();
p3.Kill();
If you want some superuser to have access to kill the process, why not let them just do it with the GUI? If there is no GUI, how are they running the program? Is it started via cmd?
Copied from my comment below:
If the user wants to be able to kill the process from the taskmanager specifically, they can use the applications tab to pick the correct process (you will need to give it a unique window title), then they can right click>Go To process and kill from there.
来源:https://stackoverflow.com/questions/14711100/change-name-of-process-in-task-manager