对不正确术语的道歉,我仍然对.NET Framework和程序设计总体上很熟悉,这使得很难提出一个特定的问题。除此之外,我正在尝试编写一些代码,这些代码将打开一个程序,然后在关闭时通过WriteLine向我报告,现在由于某种原因,当应用程序首次启动时,它会向我报告为关闭,然后打开并关闭程序,然后据报道再次关闭。重申一下,我只希望它在应用程序最初打开后向我报告。提前致谢!这是我的代码:
class MyProcess : Process
{
public void WhenExited()
{
OnExited();
}
}
static void Main(string[] args)
{
MyProcess Updates = new MyProcess();
Updates.StartInfo.FileName = System.IO.Path.Combine(Environment.CurrentDirectory, "updater.exe");
MyProcess p = new MyProcess();
p.StartInfo.FileName = System.IO.Path.Combine(Environment.CurrentDirectory, "program.exe");
p.Start();
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(myProcess_HasExited);
p.WaitForInputIdle();
p.WhenExited();
System.Threading.Thread.Sleep(1000);
void myProcess_HasExited(object sender, System.EventArgs e)
{
Console.WriteLine("Process has exited.");
}
// Exit Controll
string answer = Console.ReadLine();
while (answer != "Exit")
{
answer = Console.ReadLine();
}
}