Scheduled task programming


I'm looking for a solution to a recurrent problem, the task scheduling system under windows. I want my application to execute a certain set of functions at a given moment in a week, every week. Like, every monday morning, I want to execute my own function "functionA()".

How should I do this? I am usually using C/C++ with or without the .NET framework.

One solution would be to implement a timer for like, 5 seconds and check the time every time the timer goes to zero, but that doesnt seem to be a great solution so if any of you have a good solution to that problem please let me know.

Also, I know about the windows task scheduler, but it only allows me to run compiled executables.
Who is Participating?
Why dont you put the logic in your C program?

get the system date, look at day of week

then depending on what day it is, run the appropriate function

e.g. in C, u can use time

time_t now = time ( NULL );
struct tm date = *localtime ( &now );

then use tm_date->tm_mday or something (cant remember the exact field)

How often do u need to run these functions in any one day? If once, U can then set your task scheduler to run your pogram on a daily basis, thats it - no arguments.

with regards to timers (only necessary if function needs to be called multiple times in a day), u can find an example here

Not sure where the problem lies

If u have a C program, you obviously have to compile it in order to run it
When compilled and linked u will end up with an exe
Why cant u use that in the windows task scheduler to run your own exe
function main() will simply call your functionA

Or do you want your program to run in the background all the time, hence why you mentioned using timers.
ZarathushtraAuthor Commented:
Suppose that monday, i want to run "functionA()" and tuesday, "functionB()"
the task scheduler would go something like
ON Monday, run "myProgram.exe functionA"
ON tuesday, run "myProgram.exe functionB"

wouldnt that create overly messy code?
I was originaly looking for a program running in the background all the time, but I don't have a lot of experience dealing with elapsed time and durations in C/C++

I did it once in VB 6 with timers but it wasnt very nice since I had to reset the timer every second or so to get good precision.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.