Solved

Background process - How to

Posted on 1998-10-05
6
161 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
build html 5 client that connect to indy Tidtcpserver 3 355
Delphi Dbf export problem to a Visual Foxpro application 6 162
Help on project with Soap 10 48
Delphi 2 50
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now