Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Better function than DECLARE Sleep ... 1

Status
Not open for further replies.

dbMark

Programmer
Apr 10, 2003
1,515
US
In the past I would use this function to have the program 'wait' for another call to finish.
Code:
DECLARE Sleep IN kernel32 INTEGER dwMilliseconds
Sleep(1000) && 1 second

However, doing that could delay the response when starting or using other Windows apps. However, MsgWaitForMultipleObjectsEx function is preferred for desktop apps because it can co-exist better with other Windows apps. Here is a sample usage:
Code:
DECLARE MsgWaitForMultipleObjectsEx IN WIN32API INTEGER nCount, INTEGER @pHandles, INTEGER dwMilliseconds, INTEGER dwWakeMask, INTEGER dwFlags
MsgWaitForMultipleObjectsEx( 0, 0, 1000, 0x40, 0 ) && 1000 = 1 second
Source link:

MSDN: You have to be careful when using Sleep and code that directly or indirectly creates windows. If a thread creates any windows, it must process messages. Message broadcasts are sent to all windows in the system. If you have a thread that uses Sleep with infinite delay, the system will deadlock. Two examples of code that indirectly creates windows are DDE and COM CoInitialize. Therefore, if you have a thread that creates windows, use ... MsgWaitForMultipleObjectsEx, rather than Sleep.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top