I want my MapBasic to sleep or wait for a couple of seconds to allow another Windows program to do something. I've tried a MapInfo Knowledge Base suggestion, but it hogs the processor and slows down the other program. That means I have to allow a very long wait so the other program can finish its work. I've invented an alternative using the Windows API call Sleep, which doesn't hog the processor. I was wondering whether anyone knew whether its OK to call Sleep, before I send the MBX out to my customers...

The MapInfo Knowledge Base suggestion is this

Declare Sub Wait(byVal iSeconds as Integer)

Sub Wait(byVal iSeconds as Integer)
  Dim iEnd as Integer

  iEnd = Timer() + iSeconds
  Do while Timer() < iEnd
    ' whatever
  Loop
End Sub

But the trouble is that the Do-While loop hogs the processor. My alternative is below. The Sleep call takes the time to sleep in milliseconds. I'm mainly a Visual Basic programmer, and my VB bible for the API says Sleep is fine to use with VB. It seems to work with MapBasic too.

Declare Sleep lib "kernel32" (byval Milliseconds as Integer)
Declare Sub Wait(byVal iSeconds as Integer)

Sub Wait(byVal iSeconds as Integer)
' Use the Sleep API call to put this thread to sleep without hogging the processor
call Sleep(iSeconds/1000)
End Sub


Thanks in advance

Mark

____________________________________________________________
Mark Jackson
Cambridge Environmental Research Consultants Ltd

3 King's Parade, Cambridge, CB2 1SJ

tel: 01223 357773
fax: 01223 357492
web: www.cerc.co.uk
email: [EMAIL PROTECTED]
____________________________________________________________


********************************************************************
Cambridge Environmental Research Consultants Ltd. cannot accept any
responsibility for the accuracy or completeness of this message as it has been transmitted over a public network.


This e-mail and any files transmitted with it are private and intended
solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient, this e-mail and any accompanying files have been transmitted to you in error. You may not copy, distribute or make any other use of the information contained in them.




---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 5807



Reply via email to