I want to check if a problem that sometimes show up and sometimes not still happen. So instead closing manual the application and start again all the time is there anything that can make it automatic untill the problem will show up ? Or something that will simulate Form Closing.
How about writing a simple bat program to kill your app and start it again? Look for "Taskkill" command for console. If I have to kill notepad, I will use "taskkill /f /im notepad.exe"
You can make it to require a keypress to perform iterations and induce delay before killing of app.
Just for fun, if you really wanted to do something, try a simple C# app that does the following:
for (int i = 0; i < 100; ++i)
{
Process proc = Process.Start("ExecutablePath");
Thread.Sleep(1000);
proc.Kill();
}
You can try this
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();
}
}
Use a Timer to call a method at certain intervalls. When the Timer ticks, look if a process with the given name exists. If it exists close its main window (do not just kill it). If it does not exist, start it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.