[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

NT Timer Routine

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
rian
Asked:
rian
  • 3
  • 2
1 Solution
 
Tommy HuiCommented:
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
 
rianAuthor Commented:
Apparantly, the Sleep function does not work on a console application. Is that true
0
 
Tommy HuiCommented:
That is NOT true. I have written console applications that use Sleep. The console applications have access to most of the Win32 API.

0
 
rianAuthor Commented:
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
 
Tommy HuiCommented:
All you need is winbase.h. Make sure you are using Sleep() and not sleep().


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now