• C

Timer feature...

Hi everyone, I'm having one question and hope can find out solutio here. I need to implement a feature just like Timer control in VB. When each interval time is achieved, a function will be called to carry out some tasks automatically, without supervision of user. Basically it is similiar to tasks scheduling. Any idea on how to do this? Thanks!
lenzgeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sunnycoderCommented:
Hi lenzge,

use alarm and signals

alarm(10);

will set an alarm for 10 seconds ... after 10 seconds have elapsed, SIGALRM will be raised ... you will have to set up a signal handler for handling SIGALRM ...

this signal handler will be invoked each time SIGALRM signal is encountered

look into help pages for sigaction signal and alarm

Cheers!
Sunny:o)
0
fridomCEO/ProgrammerCommented:
Check out the documentation about SetTimer or the whole Timer API.
e.g from here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/timers.asp

Regards
Friedrich
0
lenzgeAuthor Commented:
It seems that both suggestions are having same logic: using signal to fire actions. However I'm still not clear about the syntax on doing it. For Sunny, I can't find the topic on sigaction from MSDN library; for Friedrich, the sample code in provided link is incomplete, therefore it cannot been compiled and I don't know what is missing. Can you try to post a simple sample here? Thanks to both of you.
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

sunnycoderCommented:
sigaction is a POSIX standard so windows should support it, but suprisingly, it does not ... here is some sample code from msdn for doing the same

#define _WIN32_WINNT 0X0500

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

void main()
{
    HANDLE hTimer = NULL;
    LARGE_INTEGER liDueTime;

    liDueTime.QuadPart = -50000000;

    printf("alarm application starting\n");

// Set up a 5 second timer object
    hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");
    SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, 0);

// Now wait for the alarm
    printf("waiting for alarm\n");
 
// Wait for the timer object
    WaitForSingleObject(hTimer, INFINITE);
    printf("Ring...Ring!\n");
    printf("alarm application done\n");
    exit(0);
}

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnucmg/html/UCMGch09.asp

also check this link
http://www.codeproject.com/system/timers_intro.asp?print=true
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lenzgeAuthor Commented:
It is working. Thanks!
0
lenzgeAuthor Commented:
It is working. Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

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.