Solved

Shut down and restart C# winform app

Posted on 2007-03-19
8
3,069 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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