Shut down and restart C# winform app

Hi,

How do I close my app and start a new instance? Sounds a bit contradictory to me, but I've seen it done eg when an error is raised in Office and Firefox.

Thanks
bowemcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dctuckCommented:
I've never tried it myself, but perhaps as the program closes down, it runs a small second program which will wait for that original program to end and then restart it?
0
WebstormCommented:
Hi bowemc,

try :
Application.Restart();

0
bowemcAuthor Commented:
webstorm - will this kill everything and start with a blank sheet? As you can imagine if I execute this  after a unhandled error is raised I want to kill EVERYTHING so there is 0% of any problematic issues / code / bugs hanging around. I've inconviencied the application user enough, I don't want to restart them unless I know they have a 100% fresh start.

Thanks for the speedy response :)
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

WebstormCommented:
The documentation about this function says :
Shuts down the application and starts a new instance immediately.

If you get a NotSupportedException, or it does work like you want, another solution can be :

            System.Diagnostics.Process.Start(Application.StartupPath
                + "\\myapp.exe");    // where myapp should be replaced by your executable name
            Application.Exit();
0
WebstormCommented:
I just tested the   Application.Restart();   method : the application restart as another windows process. And the old one is killed.
0
WebstormCommented:
For information : I tested it with an application using multiple threads (timer, socket listening, and WinForm).
0
bowemcAuthor Commented:
Application.Restart();  seems to be a .Net 2.0 method -> I'm using .Net1.1
0
WebstormCommented:
Then try the alternative solution i posted :

            System.Diagnostics.Process.Start(Application.StartupPath
                + "\\myapp.exe");    // where myapp should be replaced by your executable name
            Application.Exit();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.