Solved

Timer feature...

Posted on 2003-11-30
6
789 Views
Last Modified: 2010-04-15
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!
0
Comment
Question by:lenzge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9848523
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
 
LVL 24

Expert Comment

by:fridom
ID: 9848563
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
 

Author Comment

by:lenzge
ID: 9894305
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 45

Accepted Solution

by:
sunnycoder earned 50 total points
ID: 9895576
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
 

Author Comment

by:lenzge
ID: 9954621
It is working. Thanks!
0
 

Author Comment

by:lenzge
ID: 9954622
It is working. Thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

728 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