当WinFormApp即将关闭时,如何在C#中启动另一个.exe?

当WinFormApp即将关闭时,如何在C#中启动另一个.exe?,c#,windows-7,visual-studio-2017,C#,Windows 7,Visual Studio 2017,当以C#编写的WinFromApp.exe关闭时, 它最终应该启动另一个Prog.exe 重要信息,WinFromApp.exe不应等待Prog.exe的结果。 当Prog.exe运行时,WinFromApp.exe应完全关闭 [这是我第二次使用此论坛提出问题。] 我仍然用Dreamweaver MS Office VBA编写了许多程序 Visual Studio(2017)编程对我来说是全新的。因此,我还需要知道代码/代码部分的放置位置 我有来自“Welcome.cs”的as [“++…+++

当以C#编写的WinFromApp.exe关闭时, 它最终应该启动另一个Prog.exe

重要信息,WinFromApp.exe不应等待Prog.exe的结果。 当Prog.exe运行时,WinFromApp.exe应完全关闭

[这是我第二次使用此论坛提出问题。]

我仍然用Dreamweaver MS Office VBA编写了许多程序

Visual Studio(2017)编程对我来说是全新的。因此,我还需要知道代码/代码部分的放置位置

我有来自“Welcome.cs”的as [“++…+++”在代码中标记完成,包括开始。]

和Program.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32;

namespace Welcome
{
    static class Program
    {
        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Welcome());
        }
    }
}
在这里[+…+],它正在工作=非常感谢您

这个问题在这里已经有了答案:

我看了这个链接,但没有找到我问题的答案

因为正如我在问题中所写的:

Visual Studio(2017)编程对我来说是全新的。因此,我还需要知道代码/代码部分的放置位置

对不起,直到昨天,我才使用stackoverflow作为阅读器

所以我也不擅长做问题


假设您的应用程序是WinForm应用程序,您可以使用ApplicationExit事件执行此操作

首先,您需要订阅应用程序退出和FormClosing事件

Application.ApplicationExit += Application_ApplicationExit;
然后,在事件中,您可以使用Process.Start调用第二个exe

private void Application_ApplicationExit(object sender, EventArgs e)
{
    var process = new ProcessStartInfo("notepad.exe");
    Process.Start(process);
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
    var process = new ProcessStartInfo("notepad.exe");
    Process.Start(process);
}

@mjwills,你是说一个类似呼叫的环境。退出终止它?表单关闭可能有助于强制杀戮(不确定),但应用程序。退出-有办法处理它吗?谢谢你回答我的问题。#我现在已经编辑了这个问题你能再看一遍吗?
Application.ApplicationExit += Application_ApplicationExit;
private void Application_ApplicationExit(object sender, EventArgs e)
{
    var process = new ProcessStartInfo("notepad.exe");
    Process.Start(process);
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
    var process = new ProcessStartInfo("notepad.exe");
    Process.Start(process);
}