我写了监控程序用timer循环杀死进程、启动进程(被监控程序不稳定所以这么做),但我有个问题,如何在杀死进程后等待几秒钟再启动进程(我是想让被杀死的进程内存得到全部释放)、我怕万一电脑卡或其他原因使得被杀死的进程还没完全关闭就重新启动进程、、一直下去会导致内存爆满...不知道我的担心是否多余、如果不是的话该怎么解决上面的等待问题?下面是我timer里的代码:
private void timer1_Tick(object sender, EventArgs e)
{
timer11++;
Process[] proc = Process.GetProcessesByName(fileName2);
foreach (Process ps in proc)
{
ps.Kill();
} System.Diagnostics.Process p = new System.Diagnostics.Process();
//程序信息类
ProcessStartInfo Info = new ProcessStartInfo(); //设置外部程序名
Info.FileName = fileName; //设置外部程序启动进程的目录
Info.WorkingDirectory = filePath; Info.WindowStyle = ProcessWindowStyle.Maximized; try
{
//
//启动外部程序
//
p = Process.Start(Info); //等待3秒钟
// p.WaitForExit(60000);
}
catch (Exception ev)
{
MessageBox.Show(ev.Message);
}
this.label1.Text = "timer第("+timer11+")次杀死被监控程序并已重新启动,等待下一次的工作……" + DateTime.Now.ToString();
}
请各位指教!
private void timer1_Tick(object sender, EventArgs e)
{
timer11++;
Process[] proc = Process.GetProcessesByName(fileName2);
foreach (Process ps in proc)
{
ps.Kill();
} System.Diagnostics.Process p = new System.Diagnostics.Process();
//程序信息类
ProcessStartInfo Info = new ProcessStartInfo(); //设置外部程序名
Info.FileName = fileName; //设置外部程序启动进程的目录
Info.WorkingDirectory = filePath; Info.WindowStyle = ProcessWindowStyle.Maximized; try
{
//
//启动外部程序
//
p = Process.Start(Info); //等待3秒钟
// p.WaitForExit(60000);
}
catch (Exception ev)
{
MessageBox.Show(ev.Message);
}
this.label1.Text = "timer第("+timer11+")次杀死被监控程序并已重新启动,等待下一次的工作……" + DateTime.Now.ToString();
}
请各位指教!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货