Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sleep (sec 5 )      in a generic c++ code and a win32 code.

Posted on 2007-11-27
9
Medium Priority
?
921 Views
Last Modified: 2008-02-01
in some scripts it's



sleep (5000 miliseconds)


what is it in c++?
0
Comment
Question by:Troudeloup
[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
  • 2
  • +2
9 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 20358917
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 20358925
BTW, '500' is used because the function takes miliseconds - 5000ms are 5s.
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 20358930
Hi Troudeloup,

That depends on the C++ implementation.

If the library supports it, the easiest is probably to instantiate a TTimer, set the interval for 5000 ms, and let the OnTimer event handle it.  That's not a true sleep(), but allows the application to continue and to fire off a method at the 5 second mark.


Good Luck,
Kent
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Expert Comment

by:kevin_uk05
ID: 20358941
Try

void sleep(unsigned int mseconds)
{
    clock_t goal = mseconds + clock();
    while (goal > clock());
}
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20358968
I think Troudeloup is working for Windows, so the Sleep() function should work.
Another portable alternative, not exact up to the millisecond, could be:

time_t t0 = time(NULL) + 5;  // 5 seconds
while (time(NULL) < t0);
0
 

Author Comment

by:Troudeloup
ID: 20358973
jkr, this doesn't halt for 5 seconds.


#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>

using namespace std;




int main ()
{

      Sleep(25000);

      cout << "what's going n ?" << endl;

      
      
      
      return 0;
}



0
 

Author Comment

by:Troudeloup
ID: 20358977
yeah i am, for now.

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20359061
>> Sleep(25000);

that halts for 25 seconds (25,000 miliseconds)
0
 

Author Comment

by:Troudeloup
ID: 20359105
but it doesn't


note that i use it in the context of console programming
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

722 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