Jump to content
  • Advertisement
Sign in to follow this  
Lenolian

[.net] Restart application after an error.

This topic is 4859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have recently made a small file search engine and i want it to restart itself automatically whenever an error occur, like Visual Studio does. How can i achieve this ? I tried google but it didnt gave anything usefull, maybe i am just not using the right keywords. Edit : forgot to say i am using C#.

Share this post


Link to post
Share on other sites
Advertisement
One way could be, to create a thread for your tool itself and the parent thread, just forks it again, each time an error occurs...

Share this post


Link to post
Share on other sites
Wow, that were a quick answer. My browser didn't even finish to load the page after i cliked submit, crappy 56K :)

Anyway thanks, I were thinking at something like that too, I just hoped that there would be a class in the .net library that would allow it easily.

Share this post


Link to post
Share on other sites
The .Net framework contains a Process class (System.Diagnostics.Process i think) that allows you to run programs seperately from your own. You could probably use this class to simply start another instance of your program before the one in which the error occured quits.

Share this post


Link to post
Share on other sites
Another way that avoids having to restart the process would be as follows:

class Startup
{
static void Main()
{
bool running = true;
while(running)
{
try
{
RunApp();
running = false;
}
catch(Exception e)
{
// Display message about an error in the
// application, ask if it should restart
running = DisplayMessage();
}
}
}
}


There shouldn't be any issues with resources not getting cleaned up as this is handled by the runtime while unwinding the stack when the exception is thrown. As far as unmanaged resources (which you probably don't have anyway), properly use of the IDisposable interface should keep this clean as well.

Share this post


Link to post
Share on other sites
However, that method doesn't work for most type of errors that would actually require a restart, such as null pointers, divide by zero, etc. However, if you used structured exception handling, you can catch those kinds of errors, but I think it's platform dependent. There was an article about it a while back.

tj963

Share this post


Link to post
Share on other sites
Quote:
Original post by tj963
However, that method doesn't work for most type of errors that would actually require a restart, such as null pointers, divide by zero, etc. However, if you used structured exception handling, you can catch those kinds of errors, but I think it's platform dependent. There was an article about it a while back.


This is Just Plain Wrong (tm). Structured exception handling is an old, let it go the way of the dodo (like it should). The .NET Framework will quite happily catch all system-level exceptions, for example DivideByZeroException.

Also, from MSDN:
Quote:
.NET Framework Developer's Guide: Handling and Throwing Exceptions
Because execution threads routinely traverse managed and unmanaged blocks of code, the runtime can throw or catch exceptions in either managed or unmanaged code. Unmanaged code can include both C++-style SEH Exceptions and COM-based HRESULTS.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!