[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

NT Timer Routine

Posted on 1997-12-09
5
Medium Priority
?
205 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
[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
5 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

656 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