【发布时间】:2009-06-22 15:22:13
【问题描述】:
我如何在 2 或 3 分钟后杀死一个进程看看下面的代码:
class Program
{
static void Main(string[] args)
{
try
{
//declare new process and name it p1
Process p1 = Process.Start("iexplore", "http://www.google.com");
//get starting time of process
DateTime startingTime = p1.StartTime;
Console.WriteLine(startingTime);
//add a minute to startingTime
DateTime endTime = startingTime.AddMinutes(1);
//I don't know how to kill process after certain time
//code below don't work, How Do I kill this process after a minute or 2
p1.Kill(startingTime.AddMinutes(2));
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("Problem with Process:{0}", ex.Message);
}
}
}
所以我希望 IE 窗口在 2 分钟后关闭
【问题讨论】:
-
p1.WaitForExit(60000); // 日期时间 endTime2; p1.CloseMainWindow(); //endTime2 = p1.ExitTime; p1.Close();