Application Restart or Reload Urgent....

  • Thread starter Thread starter Chris Calhoun
  • Start date Start date
C

Chris Calhoun

Does anyone know how to restart an application from itself? Or is there a
way to completely reload an application form code simulating a restart?

Thanks in Advance!
 
If you've written your app in VB.NET it might need a slight rewrite to match
a C# application style. But if you've written it in C#, you can put a try
catch around the
Application.Run(new Form1());

Portion, and basically in the catch do whatever recovery you want and recall
the above.

- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
 
Note reloading your form only simulates a restart, and it doesn't carry with it
all of the features of an actual process restart. If you truly need to restart
your
application, then you should probably take a good hard look at Process.Start
and the Environment class. You'll be able to get the arguments your application
was started with and pass those to a new instance of your app.

If you need synchronization between unloading/loading, you can use a Mutex
to allow your existing application to shut down and release resources required
for the second instance to completely load. A great example would be a
listening port, since two apps can't share that sort of resource.
 
Back
Top