Archived

This topic is now archived and is closed to further replies.

edotorpedo

Need to run app at certain time, how?

Recommended Posts

Hi, I want an application to run once a week at a certain time (down to minutes will do). Is the only way to do this by permanently running the app and check every minute if the time has come? Is there any trick to do this, without having any manual interference? What would be the best method (or control) to do this. Thanks, Edo

Share this post


Link to post
Share on other sites
If you think, the computer has to check this line of code:

if( currentTime == timeToRunApp)
RunApp();

..

So, the easies way is to make a whileloop:

int WinMain( ... )
{
nexAppRun = LoadFromCfg( NEXT_APPRUN );

while( currentTime < nextAppRun )
{

currentTime = GetCurrentTime();
sleep(60000); // only check once a minute, to not slow the computer down.
}

GoGoGo();
}

But there might be some OS specific routines for this. There are one in Windows that I know of, but I don''t know if you have to set it manually, or if you can modify the register.

----------------------------------------------
Petter Nordlander

"There are only 10 kinds of people in the world. They who understand binary and those who do not"

Share this post


Link to post
Share on other sites
quote:
Original post by edotorpedo
I want an application to run once a week at a certain time (down to minutes will do). Is the only way to do this by permanently running the app and check every minute if the time has come?

No. That''s a dreadful way of doing it. Your OS will probably have some way of scheduling jobs for certain times. e.g., various versions of Windows have Task Scheduler, *nix has cron, etc.

Share this post


Link to post
Share on other sites

But you have to input date and time into Task Scheduler manually don''t you? I want it to be automatic and controlled from within the app. How do virus scanners schedule their weekly system scan for example? Has to be a better way than checking time every minute.

Edo

Share this post


Link to post
Share on other sites
If you are using Windows, i believe you can make it generate a WM_TIMER message in an intervall that you can specifiy. Than you can catch this message in your apps loop. Of course it needs to run somewhere in the background to do so but that wont use up much processing time.
That''s how i solved a similar problem but there may be better ways.

Share this post


Link to post
Share on other sites
quote:
Original post by edotorpedo
But you have to input date and time into Task Scheduler manually don''t you?

You don''t *have to*. You can programmatically control the Task Scheduler via COM. You could also possibly use the `at'' command.
quote:

I want it to be automatic and controlled from within the app. How do virus scanners schedule their weekly system scan for example?

Norton Antivirus Client runs as a Windows service, with its own internal scheduler. However, you''re asking how an expensive (in developmental cost) and sophisticated piece of s/w performs something which you will probably be satisfied to achieve in a straightforward and fairly ad-hoc way. Norton have probably had many professional developers working on their s/w!

You probably don''t need to write a Service, but if you did want to, I''d recommend looking at Python + the Python Win32 extensions, which has a ServiceFramework class that makes it very simple to achieve.
quote:

Has to be a better way than checking time every minute.

The question is how does your program decide when it is next to run? You''re making it sound like the task is to run at irregular intervals, and its not clear how the task decides when next to invoke itself. The way such problems tend to be solved in the real-world is that a task will be scheduled at regular intervals to process some input data, but actual input data might only be present sometimes. If there is no input data, then the regular schedule will not do anything. Why is running at regular intervals not sufficient to solve your problem?

Share this post


Link to post
Share on other sites

No, I need the application to run at regular intervals (once a week) on a pre-set time. Very simple. Problem is, how do I get an event fired (or application runned) when the time comes. My first instinct was to use the VB timer control and just check each minute if this minute is the specified pre-set time to run the routine.

Are there any resources on programming the task scheduler via COM (I''ve never worked with COM objects before, but I''m doing this app in C#).

Thanks,

Edo

Share this post


Link to post
Share on other sites
Scan the registry for something that has to do with the Task Shedular, write down the location of the data fields. Now make some changes in the sheduled jobs and see how it affects the registry. Do this multiple times until you have enough data to be sure to know how the shedular saves its jobs. If you know that it is trivial to do it yourself.

Share this post


Link to post
Share on other sites
quote:
Original post by edotorpedo
No, I need the application to run at regular intervals (once a week) on a pre-set time. Very simple. Problem is, how do I get an event fired (or application runned) when the time comes.

You go to `Scheduled Tasks'', choose `Add Scheduled Task'', and you set it up to run your program once a week at the desired time.
quote:

Are there any resources on programming the task scheduler via COM (I''ve never worked with COM objects before, but I''m doing this app in C#).

Check MSDN.
quote:
Original post by Rob Lemmens
Scan the registry for something that has to do with the Task Shedular, write down the location of the data fields. Now make some changes in the sheduled jobs and see how it affects the registry.

No, don''t do that. Read the API specification.

Share this post


Link to post
Share on other sites