🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1332

Console applicaton and sleep()

#1332
From: Andre Steenveld
Date: Tue, 18 Sep 2007 17:51
26 lines
2072 bytes
Hi,

I've a problem with a console application and the Sleep() api call.

What I need/want, in some states of the program, is to release the timeslice 
in a console application while it is waiting on (non blocking) user input. 
For that I need access to usleep(msec) or Sleep(msec). A call to sleep(sec) 
is not realy an option. Users will notice a delay of one second most 
certenly.

The alternative is to do busy-waiting and keep the processor load at 100%. 
Not a nice option.
Another alternatice is to switch between blocking and non-blocking input 
which doesn't sound atractive to me. (more code prone to buggy behaviour)

Since the application is a console application I can't include <windows.h>. 
If I do, a load of compile errors is the result.
But to use sleep(), usleep() or Sleep() I must include <windows.h> according 
to the documentation.

Does someone know how to call a windows API call from a console application? 
Does someone have a suggestion to tackle this problem?

Kind regards,

Andre Steenveld. 
Technical Details
Message-ID: <46f01013@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!eweka.nl!lightspeed.eweka.nl!194.134.4.77.MISMATCH!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,12ae2dc26e53d1eb,start
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Andre Steenveld" <a.steenveld@id.umcn.nl>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Console applicaton and sleep()
Date: Tue, 18 Sep 2007 19:51:11 +0200
Lines: 27
MIME-Version: 1.0
Content-Type: text/plain;
 format=flowed;
 charset="iso-8859-1";
 reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Windows Mail 6.0.6000.16480
X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16480
NNTP-Posting-Host: 77.251.117.105
Message-ID: <46f01013@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1190137875 77.251.117.105 (18 Sep 2007 10:51:15 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!eweka.nl!lightspeed.eweka.nl!194.134.4.77.MISMATCH!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail