English 中文(简体)
从一组青少年申请中清洁地杀害一名青少年申请
原标题:Cleanly killing a console application from within a group of console applications

我有一个窗口表格,利用同一方案(电话方案,任何次数)提供多种假释申请。

process.start().  

我正在寻找一种办法,确定申请的具体操作,并清白地加以杀害(即清理了第5个方案进程,但留下了所有其他进程)。 我能够确定每个不同的方案过程。 通过程序启动时发放的婴儿,但我无法通过呼吁以外的任何方式结束申请。

process.kill() 

未对申请进行清理。

我认为我不能使用

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); // will throw on Add if duplicate id, prevent duplicate
ExecutionViewModel.NewRun(details); // add to the view model

process.Start();

如果有的话,则是一个确定每个进程的统一数据库。

在整整整整类中,我有通过指挥程序实施的法典,而这种程序只是通过指挥程序启动(例如电话方案、提供组合变量等)。

是否有办法可以干净地结束这些进程? 我认为,在我想要杀手的时候,有一个叫作的事件可能奏效,但迄今为止,由于我无法具体说明我想结束哪些进程,我一直未能找到这一想法。

** 本文件迟交。 EDIT——我处理我试图冒犯但并未奏效的事件的守则。

主要窗口

 public void KillOne() {
     foreach (var details in _runs.Values) {
         if(details.IsSelected) {
             StrategyStateManager.SessionClosed(this, details.RunId);
                } } }

《战略》中的法典 (用于持有可变数和用于方案的活动的中产阶级)

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");
        }
    }
最佳回答

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.

当然,这假定,你为该方案扫地关闭创造了条件。

广播数据表当然得到保证,但我的经验是,这些图表在单一系统中是可靠的。 如果你遇到问题,你可以把主要方案发送数据表,等待一段时间才能看到方案是否关闭,如果不再如此,就会再次发送数据表。

Another possibility is to create a named EventWaitHandle 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 WaitOne 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.

问题回答

就像你将在你自己的单独法典中有一个明确的国家,由你们想要终止这一进程的分进程管理。 为什么不请你打电话<条码>。 程序.GetCurrentProcess().Kill(); 或甚至Process.GetCurrentProcess();Close( at the end of that Code path?

这样一来,完成执行工作,就会结束/结束,其余进程将继续如期进行(直至其结束点)。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签