Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Scheduled task programming

Posted on 2006-05-11
Medium Priority
Last Modified: 2010-04-17

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.
Question by:Zarathushtra
  • 2
LVL 65

Expert Comment

ID: 16657480
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.

Author Comment

ID: 16657518
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.
LVL 65

Accepted Solution

rockiroads earned 500 total points
ID: 16657590
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


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

581 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