Background process - How to

I wrote a program that runs unattended in public places. It crashes on occasion, strange error messages, etc.. I would like to write a small application that would constantly look for my application and reboot if it disappears.  I want this background process to be very small, no form, etc...

How can I do that.  

Thank you.
Who is Participating?
scrapdogConnect With a Mentor Commented:
You could probably do it without a background process.  Try changing your main module's code to look like this:

program Project1;

  Windows,                      // don't forget to include Windows!!!
  Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

  Application.CreateForm(TForm1, Form1);

If your application raises an exception, Windows will restart.


Make sure the program is in your startup folder when using this method though!!  

I assumed that "reboot" meant reboot the machine (probably your best bet if the machine will be unattended).
alexandramAuthor Commented:
What if it crashes so bad that this code does not even get a chance to be executed ? I realize that these should not happen but I just want to be safe. That's why I was thinking of a separate process.  
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

If you use a separate process, consider this:

1.  Your main program raises an exception, and stops operating normally.  However, the main program is still running.

2.  The background process checks to see if it is running.  It is, so do nothing.

Just because a program crashes doesn't mean that it will close itself automatically.  If it is still there, your background process will think it is still running normally.

If you use the try..except method, without a separate process, any exceptions that your applications raise will be passed to the ExitWindows statement.

Using a separate process would be would have to account for HOW the application stopped.  If you closed it normally, you would first have to close the background application to stop checking, or your program would reboot every time you closed it!!

If it crashes so bad that the except statement cannot be executed, chances are that the crash occurred due to an external source.  The except statement should catch almost everything.

   You are looking for a band-aid. Make your application more robust, and find a permanent solution (cure) rather than treating symptoms (which inevitably creates more bugs -- and there is a lot of research that supports this fact). One of the fundamental tenets of quality-driven software development is fixing what you have already before continuing developing.

Best of luck


PS _Code Complete_ by Steve McConnell is a book you must check out.
alexandramAuthor Commented:
Thank you. The proposed solution seems to work well. You convinced me - no background process.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.