Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Timer feature...

Posted on 2003-11-30
6
Medium Priority
?
799 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 45

Accepted Solution

by:
sunnycoder earned 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops 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.

610 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