Solved

NT Timer Routine

Posted on 1997-12-09
5
197 Views
Last Modified: 2010-04-10
I am trying to write a C++ console program running in NT Server-DOS process which would be able to do a countdown of time defined by the user as well as exit the countdown based on the user input. The current program takes a lot of system CPU resource to countdown to a pre-determined time interval. DOes WIN32 provide an API which will return time without eating the CPU resource.
0
Comment
Question by:rian
  • 3
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 50 total points
ID: 1175524
One way to do it is to use SetTimer() and provide a callback function. This function will get called after the time has expired. Another possibility would be to use Sleep(). This puts the entire process to sleep for the entire length you specified. Upon which, your program continues from the point of calling Sleep().

0
 

Author Comment

by:rian
ID: 1175525
Apparantly, the Sleep function does not work on a console application. Is that true
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1175526
That is NOT true. I have written console applications that use Sleep. The console applications have access to most of the Win32 API.

0
 

Author Comment

by:rian
ID: 1175527
I do not dispute what u are saying. Unfortunately, I have not been able to compile with the sleep API. I have included windows.h, winbase.h. Also, added Kernel32 in the link lib setting.

Could u tell me which header file is required to compile. Currently, the compiler tells me that sleep in a unknown identifier.
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1175528
All you need is winbase.h. Make sure you are using Sleep() and not sleep().


0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

856 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