I have two desktop applications. After closing the first application, the first application will start the second application.
How do I start the second application after finishing first application?
My first application creates a separate desktop.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use .NET’s Process Class to start a process as other people described. Then the question is when to call.
In most cases, using either
Form.ClosingorForm.Closedevent seems to be an easy choice.However, if someone else can handle the event and can set
CancelEventArgs.Cancelto true, this may not be the right place to do this. Also,Form.ClosingandForm.Closedevents will not be raised whenApplication.Exit()is called. I am not sure whether either of events will be raised if any unhandled exceptions occur. (Also, you have to decide whether you want to launch the second application in case ofApplication.Exit()or any unhandled exception).If you really want to make sure the second application (App2) launches after the first application (App1) exited, you can play a trick:
The sample console app attached below shows a very simple case: my sample app launches the notepad first. Then, when the notepad exits, it launches mspaint and exits itself.
If you want to hide the console, you can simply set the ‘Output Type’ property from ‘Console Application’ to ‘Windows Application’ under ‘Application’ tab of Project Property.
Sample code: