I have a window form that creates several console applications of the same program (it calls program.exe as many times as necessary) with
process.start().
I am looking for a way to identify a specific application launch and kill it cleanly (i.e. just close the fifth program.exe process, but leave all other processes running). I can identify each individual program.exe process through the identifiers that were specified when the processes started, but I can not close the application in any way except by calling
process.kill()
which does not perform a clean application close.
I believe that I can not use
process.CloseMainWindow()
( , ). , , , , .
, , , .
:
Process process = new Process();
process.StartInfo = info;
ExecutionDetails details = new ExecutionDetails(run_id, process, info, session_type, strategy_type, name, ExecutionViewModel);
lock (_runs)
_runs.Add(run_id, details);
ExecutionViewModel.NewRun(details);
process.Start();
run_id - GUID, .
, , , (.. , ..).
, ? , , , , , , , .
** EDIT - , , .
public void KillOne() {
foreach (var details in _runs.Values) {
if(details.IsSelected) {
StrategyStateManager.SessionClosed(this, details.RunId);
} } }
StrategyStateManager ( )
public delegate void StrategyCloseEventHandler(object sender, StrategyCloseEventArgs e);
public static void SessionClosed(object sender, Guid id)
{
if(CloseSession != null)
CloseSession(sender, new StrategyCloseEventArgs(id));
}
public class StrategyCloseEventArgs : EventArgs
{
private readonly Guid id;
public StrategyCloseEventArgs(Guid run_id)
{
id = run_id;
}
public Guid GetRunID()
{
return id;
}
}
,
StrategyStateManager.CloseSession += (closeStrategy);
void closeStrategy(object sender, StrategyCloseEventArgs e)
{
if (e.GetRunID() == run_id)
{
strategy.cleanupForShutdown();
DBSaverSimple.shutdownAll();
logger.Warn("Simulation run stopped by user");
}
}