Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Shut down and restart C# winform app

Posted on 2007-03-19
8
Medium Priority
?
3,318 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
Industry Leaders: 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

715 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