digitalmars.D.learn - More updated question about Sleep/msleep/usleep
- BeschBesch (20/20) Mar 22 2014 Hello,
- Adam D. Ruppe (3/3) Mar 22 2014 import core.thread;
- Adam D. Ruppe (10/10) Mar 22 2014 This will work:
Hello, I know there are severel threads concerning "Wait", "Pause", "Sleep", a.s.o but most of them were created in 2007 or similiar. It seems D has changed a lot because when I try to call sleep/msleep (example), the compiler cannot find it (ERROR: undefined indentifier). import std.stdio; /// .... other imports as well import std.c.time; main_bock() { //// init and things sleep(1); // not found std.c.time.sleep(2); // not found as well std.c.time.msleep(1000); // nope... /// continued code } So, is there a newer version? I get a hint for thread.sleep but this may be a member function. Also, i suppose I MAY use Sleep() from windows.h, if there is no other option.
Mar 22 2014
This will work: import core.thread; void main() { Thread.sleep(5.seconds); } sleep is a member of Thread, but it is static so you can easily call it to sleep the current thread. The argument is a Duration, which is most easily constructed with the .seconds, .msecs, .minutes, etc. helper functions like I did here.
Mar 22 2014