Scheduled task programming

Posted on 2006-05-11
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
    LVL 65

    Expert Comment

    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

    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

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    729 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

    20 Experts available now in Live!

    Get 1:1 Help Now