我想检查一个有时会出现但有时不会发生的问题。因此,不是手动关闭应用程序并一直重新启动,有什么可以让它自动运行,直到问题出现?或者可以模拟表单关闭的东西。
问问题
315 次
4 回答
0
编写一个简单的 bat 程序来杀死你的应用程序并重新启动它怎么样?寻找控制台的“Taskkill”命令。如果我必须杀死记事本,我将使用“taskkill /f /im notepad.exe”
您可以使其需要按键来执行迭代并在杀死应用程序之前引起延迟。
于 2012-08-07T20:35:55.877 回答
0
只是为了好玩,如果您真的想做某事,请尝试一个简单的 C# 应用程序,它执行以下操作:
for (int i = 0; i < 100; ++i)
{
Process proc = Process.Start("ExecutablePath");
Thread.Sleep(1000);
proc.Kill();
}
于 2012-08-07T20:36:51.160 回答
0
你可以试试这个
Timer timer;
public void StartTimer()
{
timer = new Timer();
timer.Interval = 5000; // 5 seconds
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
Process[] p = Process.GetProcessesByName("TheApp");
if (p.Length == 0) {
// Restart the app if it is not running any more
Process.Start(@"C:\Programs\Application\TheApp.exe");
} else {
p[0].CloseMainWindow();
}
}
使用 Timer 以特定间隔调用方法。当计时器滴答作响时,查看是否存在具有给定名称的进程。如果它存在关闭它的主窗口(不要只是杀死它)。如果它不存在,请启动它。
于 2012-08-07T20:43:42.163 回答