Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 276983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:00:11+00:00 2026-05-12T01:00:11+00:00

What is the simplest way to write a timer in C/C++? Hi, What is

  • 0

What is the simplest way to write a timer in C/C++?

Hi,

What is the simplest way to write a timer, say in C/C++? Previously I used a for loop and a do-while loop. I used the for loop as a counter and the do-while loop as a comparison for “end of time”. The program worked as I wanted it to, but consumed too much system resources.

I’m looking for the simplest way to write a timer.

Thank you!

EDIT:

The program works on a set of servers both Linux and Windows, so it’s a multiplatform environment. I dont want to use the unsleep or sleep function as I’m trying to write everything from scratch.

The nature of the program: The program counts power time and battery time on systems.

EDIT2:

OK, it seems that this caused some confusion so I’m going to try to explain what I have done so far. I’ve created a program that runs in the background and powers off the system if it’s idle for a certain amount of time, it also checks for the battery life on a specific system and goes to stand by mode if the system has been running on battery for a while. I input the time manually so I need a timer. I want to write it from scratch as it’s a part of a personal project I’ve been working on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T01:00:12+00:00Added an answer on May 12, 2026 at 1:00 am

    Your best bet is to use an operating system primitive that suspends the program for a given amount of time (like Sleep() in Windows). The environment where the program will run will most likely have some mechanism for doing this or similar thing. That’s the only way to avoid polling and consuming CPU time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using configuration manager in the simplest way: Read: ConfigurationManager.AppSettings[Foo] Write: Configuration config =
What is the simplest way to reverse the case of all alphabetic characters in
What's the simplest way to jump to a file somewhere in my source tree
What is the simplest way to create a HTTP proxy with Python? As far
what is the simplest way to upload multi images (like 30-50) at once using
I'm trying to write the following Perl subroutine. Given are an array a of
I have a C++ application that needs to communicate to a C# application (a
I'm working on a project which has multiple similar code paths which I'd like
My library needs to read-in big-endian integers (4-bytes) and convert them to the endian
I am currently facing a scenario that I am unsure what is the best

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.