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:
- Start app.exe
- Stop/shutdown app.exe and s开发者_Go百科tart another.exe from app.exe
- 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:
- "app.exe" starts
- "app.exe" spawns "another.exe", and then exits
- "another.exe" starts
- "another.exe" spawns "app.exe", and then exits
or:
- "monitor.exe" starts
- "app.exe" starts
- "app.exe" exits
- "monitor.exe" detects that "app.exe" exited, and spawns "another.exe"
- "another.exe" starts
- "another.exe" exits
- "monitor.exe" detects that "another.exe" exited, and spawns "app.exe"
If "app.exe" should still start "another.exe", here's a variant:
- "app.exe" starts
- "app.exe" spawns "monitor.exe" and "another.exe", then exits
- "another.exe" starts
- "another.exe" exits
- "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.
精彩评论