Reputation: 135
I want to Restart my application. It is working fine with Application.Restart();
But I want to add time delay in this case as it restarting application very rapidly and I want it to take time to restart the application.
private void lbllaunch_Click(object sender, EventArgs e)
{
Application.Restart();
}
Upvotes: 1
Views: 965
Reputation: 96
Since I'm just assuming that you are using windows forms by the syntax of your example code, Thread.Sleep('time')
should do the trick for you.
If you want to make the window disappear and then restart itself after the delay you could try and use Form1.Visible = false
and then the Sleep method in your Application.restart method, or include those into a helper function like:
void restartApplication(Form form1)
{
form1.Visible = false;
Thread.Sleep(300);
Application.restart();
}
And then set the form to visible again. This solution isn't very clean tough.
I'd recommend using multithreading. You can set up another thread, that closes your application, pauses and then restarts it. This won't leave your main application in that weird state where it's open but not working.
An instruction on how to create new Threads can be found here.
Upvotes: 2