Solved

Shut down and restart C# winform app

Posted on 2007-03-19
8
2,897 Views
Last Modified: 2009-05-21
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
0
Comment
Question by:bowemc
  • 5
  • 2
8 Comments
 
LVL 7

Expert Comment

by:dctuck
ID: 18749627
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
 
LVL 13

Expert Comment

by:Webstorm
ID: 18749676
Hi bowemc,

try :
Application.Restart();

0
 

Author Comment

by:bowemc
ID: 18750341
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
 
LVL 13

Expert Comment

by:Webstorm
ID: 18750449
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 13

Expert Comment

by:Webstorm
ID: 18750632
I just tested the   Application.Restart();   method : the application restart as another windows process. And the old one is killed.
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 18750645
For information : I tested it with an application using multiple threads (timer, socket listening, and WinForm).
0
 

Author Comment

by:bowemc
ID: 18755261
Application.Restart();  seems to be a .Net 2.0 method -> I'm using .Net1.1
0
 
LVL 13

Accepted Solution

by:
Webstorm earned 500 total points
ID: 18755667
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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now