Application restart...

  • Thread starter Jacek Jurkowski
  • Start date
J

Jacek Jurkowski

In a FMain of below application I'm throwing an Exception.
It's catched by a catch section and application restarts.
But in a reastarted application try section doesn't work no longer.
Error throwed by FMain is no longer catched and causes a
last chance CLR erception handler. Why?

[STAThread]
public static void Main(string[] pStartupParameters)
{
try
{
FMain main = new FMain();
Application.Run(main);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
Application.Restart();
}
}
 
O

Oleg Yevsyukov

Just try to change your code like the following.

[STAThread]
public static void Main(string[] pStartupParameters)
{
FMain main = null;
//
try
{
main = new FMain();
Application.Run(main);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
Application.Restart();
}
}
 
D

David Levine

As Another Poster pointed out, the call to Restart is in the catch block.
I'd change the code to this...

bool _wantsToExit;
[STAThread]
public static void Main(string[] pStartupParameters)
{
done = false;
while ( !done )
{
try
{
FMain main = new FMain();
Application.Run(main);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
if ( _wantsToExit )
done = true;
}
}
}

where "_wantsToExit" is a boolean set somewhere else in your application
when the user is done and wants to exit the app.
 
J

Jacek Jurkowski

You'r code works but ... every secound time.
I mean after first restart works , secound doesn't , third works , fouth
doesn't ... and so one ...
 
D

David Levine

Without seeing your code it's impossible to know why. The restart routine
must have problems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top