I have a application that needs to run all day but sometimes it gives a exception and then the application crashes. If that happends the devices connected to the application cannot do their work.
What I need to do is restart the application when I crashes but I dont want to make another program to do that.
This is what is what I think I need to do:
static void Main(string[] args)
{
try
{
if (!Environment.UserInteractive)
{
ServiceBase.Run(new WebDaemonService(HttpClass.StartListening));
}
else
{
HttpClass.StartListening();
}
}
catch(Exception ex)
{
Restart();
}
}
But how do I make a restart function, do I just call the main class again or do I need to do something else.
The if else in the try is to check if the application needs to start as a windows service or as a application.
Can someone explain to me how I can make a restart function?