• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

Timer routine

Hi all!

Can anyone please tell me how I can make a tiny timer routine which reads the clock on the computer and prints out text in given intervals? Ie after every 5 or 10 seconds (something like an alarm clock...) Must be in plain cpp for a console window project i'm working on...

Sunb!

0
Sunblock
Asked:
Sunblock
1 Solution
 
poor_guyCommented:
void doTimer()
{
  while(true)
  {
    CTime t = CTime::GetCurrentTime();
    CString cstrCurrTime = t.Format(_T("%b/%d/%Y,%H:%M"));
    cout << cstrCurrTime;
    if (isExit == true)
    {
      break;
    }
    sleep(5000);
  }
}

This function will go to sleep for 5 seconds and loop until some other thread has set the isExit variable to true. You need use MFC for this.

Hope this helps.
0
 
CleanupPingCommented:
Sunblock:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
SunblockAuthor Commented:
I think this is a good routine giving me just what I wanted...
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

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