Solved

Shut down and restart C# winform app

Posted on 2007-03-19
8
3,211 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

635 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