Solved

Timer feature...

Posted on 2003-11-30
6
755 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Do email signature updates give you a headache?

Are you constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
posix semaphore deadlock 13 114
stack 22 159
Best UNIX-compatible free C compiler for Windows or Mac 6 237
How to build c program using make in mingw environment? 9 54
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 nested-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

914 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

12 Experts available now in Live!

Get 1:1 Help Now