Restarting an application ...

  • Thread starter Thread starter Jacek Jurkowski
  • Start date Start date
J

Jacek Jurkowski

Could anybody help me to write proper
code to restart my application?

public static void OnRestartRequest()
{
...
}

Restart is needed after exception handled and
may occur anytime in application life time ...
 
Jacek,

In this case, you would probably need another application monitoring the
original application. Of course, you run into the problem of what happens
if the application monitoring the application that originally was running
breaks down.

All in all, you should probably not do this, and let the user restart
the app, logging all information necessary to track down the issue at a
later date.

Hope this helps.
 
Alternatively you could write an application that starts up and only runs
the original application...

So you call in your orginal app:

// in the Main Form
public static void OnRestartRequest()
{
Process.Start ( "Restarter.exe" );
Close(); // or Application.Exit() ??
}


Then have the Restarter app simply call your original app, wait a few secs
maybe, before it closes...

public static void Main()
{
System.Threading.Thread.Sleep ( 3000 ); // time for old app to shut
down
Process.Start ("FirstApp.exe" );
}


Not very neat though... You should probably look at the reasons your wanting
to restart the application in the first place.





Nicholas Paldino said:
Jacek,

In this case, you would probably need another application monitoring
the original application. Of course, you run into the problem of what
happens if the application monitoring the application that originally was
running breaks down.

All in all, you should probably not do this, and let the user restart
the app, logging all information necessary to track down the issue at a
later date.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jacek Jurkowski said:
Could anybody help me to write proper
code to restart my application?

public static void OnRestartRequest()
{
...
}

Restart is needed after exception handled and
may occur anytime in application life time ...
 
Back
Top