Solved

Background process - How to

Posted on 1998-10-05
6
160 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

21 Experts available now in Live!

Get 1:1 Help Now