Solved

NT Timer Routine

Posted on 1997-12-09
5
191 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

708 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

15 Experts available now in Live!

Get 1:1 Help Now