Solved

Background process - How to

Posted on 1998-10-05
6
164 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:alexandram
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 120 total points
ID: 1341860
You could probably do it without a background process.  Try changing your main module's code to look like this:


program Project1;

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

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  try
    Application.Run;
  except
    ExitWindows(EW_RESTARTWINDOWS,0);
  end;
end.




If your application raises an exception, Windows will restart.

~Scrapdog

0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1341861
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).
0
 

Author Comment

by:alexandram
ID: 1341862
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.  
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:scrapdog
ID: 1341863
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 messy...you 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.

0
 
LVL 1

Expert Comment

by:Edo082297
ID: 1341864
Hello
   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

Edo

PS _Code Complete_ by Steve McConnell is a book you must check out.
0
 

Author Comment

by:alexandram
ID: 1341865
Thank you. The proposed solution seems to work well. You convinced me - no background process.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

761 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question