プロセスが終了しないことを保証
1559 ワード
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace ConsoleApplication2
{
class Program
{
static void Main()
{
Test a = new Test();
Console.ReadKey();//
}
}
class Test
{
private Process myProcess = new Process();
public Test()
{
myProcess.StartInfo.FileName = "iexplore.exe";
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new EventHandler(Process_Exited);
myProcess.Start();
}
public void Process_Exited(object sender, EventArgs e)
{
try
{
myProcess.WaitForExit();
Console.WriteLine(" : {0}\r
" +
" : {1}\r
", myProcess.ExitTime, myProcess.ExitCode);
}
finally
{
myProcess.Refresh();
myProcess.StartInfo.FileName = "iexplore.exe";
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new EventHandler(Process_Exited);
myProcess.Start();
}
}
}
}
機能:常にIEウィンドウを開き、タスクマネージャを通して終了後も同様