简体   繁体   中英

How can i make that my application will close and start and close automatic over and over again?

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();
}

如果要模拟用户行为,则应尝试使用AutoITAHKSIKULI

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM