Writing a scheduler program

Please discuss general Delphi programming topics here.

Writing a scheduler program

Postby RSieffert » July 21st, 2011, 3:50 am

Need advice on a Delphi programming problem - I need to develop a Delphi program that will be run by the Windows scheduler every 15 minutes, and when it runs it will call a web service, put some data into the database, and then exit. So that raises some questions:

1) Where do I put the code that needs to execute automatically? In the FormActivate routine of the startup form doesn't seem right, but that's all I can think of.

2) What will happen if the program hits some sort of problem and displays a pop-up error dialog? Because it is being run by the scheduler, not a person, no one will see the dialog box and it will just sit there. How do I deal with that?

3) In an attempt to deal with the previous issue I tried setting up a timer to trigger 10 minutes after startup and then put "Application.Terminate" or "Close" in the OnTimer event, but if the program is displaying an error dialog box when the timer fires that causes it's own pop-up error box that says "Object reference not set to an instance of an object." So the program continues to hang.

Thanks in advance for any advice.
RSieffert
Member
Member
 
Posts: 2
Joined: July 21st, 2011, 3:37 am

Re: Writing a scheduler program

Postby Kambiz » July 21st, 2011, 8:18 pm

1) Use command line parameters to direct your program to register to or unregister from Task Scheduler, or to run the task. You can use either Task Scheduler COM Interfaces or Task Scheduler command line parameters to register/unregister your program.

2) A convenience way to deal with errors is writing the error messages in the Windows event log.

3) Your program should terminate gracefully after registration, unregistration, and running the task. You do not need a timer, the Task Scheduler is your timer.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Writing a scheduler program

Postby RSieffert » August 1st, 2011, 12:52 pm

Thanks for your advice. I'll have to try it out to see if it covers all of my needs for this project.
RSieffert
Member
Member
 
Posts: 2
Joined: July 21st, 2011, 3:37 am


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron