开发者

How to stop an application?

I have an application and from, In this application I have to start another process by shutting down the current application and after the completion of the process again start the application. The flow is as follows, suppose I have an application app.exe, and another application another.exe, so I have to do following:

  1. Start app.exe
  2. Stop/shutdown app.exe and s开发者_Go百科tart another.exe from app.exe
  3. When another.exe completes, stop/shutdown another.exe and start app.exe from another.exe

Anyone please provide me some clue of how to do it?


You need to either make "another.exe" restart "app.exe" before it exits, or have a third program monitor the first two and restart "app.exe" when "another.exe" exits.

So either:

  1. "app.exe" starts
  2. "app.exe" spawns "another.exe", and then exits
  3. "another.exe" starts
  4. "another.exe" spawns "app.exe", and then exits

or:

  1. "monitor.exe" starts
  2. "app.exe" starts
  3. "app.exe" exits
  4. "monitor.exe" detects that "app.exe" exited, and spawns "another.exe"
  5. "another.exe" starts
  6. "another.exe" exits
  7. "monitor.exe" detects that "another.exe" exited, and spawns "app.exe"

If "app.exe" should still start "another.exe", here's a variant:

  1. "app.exe" starts
  2. "app.exe" spawns "monitor.exe" and "another.exe", then exits
  3. "another.exe" starts
  4. "another.exe" exits
  5. "monitor.exe" detects that "another.exe" exited, and spawns "app.exe", then exits


Here how to stop current process

Process.GetCurrentProcess().Close();

Of course call it once you have started another.exe with

Process.Start(...).


I think this is what your looking for

Process.Start("My Process");

            Process processToClose = Process.GetProcessById(your Process ID);
            processToClose.Kill();

Remember to include:

Using System.Diagnostics;

If these dont suit your needs check out the other methods in the Process class, I'm sure something will catch your eye.


What you need is a third exe that stops/start your main application. Once app.exe is closed it can't execute anything.

So try the following:

write a applicationSwitcher.exe that helps you to open/close applications and switch to your main application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜