Reputation: 15344
I have designed a form and on FormClosed event I am restarting the Application by Application.Restart();
Now question is
Upvotes: 0
Views: 688
Reputation: 707
The restarted application is a new process, so it is also a completely new thread.
To close use; Application.Exit()
To Kill: Process.GetCurrentProcess().Kill();
EDIT - Added Kill!
Upvotes: 1
Reputation: 52518
The current application will be Closed/Shutdown, and a new process (with the same startup arguments) will be created.
You can prevent the closing of the current application, by cancelling the close in a FormClosing event (from an open form). Even if you can cancelling the shutdown, the new appliction will be started, and you will end up by having two instances of your application active.
Upvotes: 0
Reputation: 6686
@Javed i think the best choice will be start new instance of your application using Process while closing and give your first instance to die in peace;)
Upvotes: 0
Reputation: 24132
The application is restarted on a new thread.
I would work with the FormClosing Event
and set the FormClosingEventArgs.Cancel = true
when I want the application not to actually be closed, and let it go when it has to be closed.
public void frmMyForm_FormClosing(object sender, FormClosingEventArgs e) {
if ("frmMyForm has to be closed and the application closed")
e.Cancel = true;
// else the e.Cancel will never be changed, then the application is closed normally.
}
The FormClosing Event is called when you make a call to frmMyForm.Close()
.
Hope I understood the question right.
Upvotes: 0