Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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



sleep (5000 miliseconds)


what is it in c++?
0
Comment
Question by:Troudeloup
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

916 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