devxlogo

Use The Sleep API Function Instead Of DoEvents

Use The Sleep API Function Instead Of DoEvents

When in NT or Windows 95, use the Sleep API function instead of DoEvents.DoEvents does this:

 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {	TranslateMessage(&msg);	DispatchMessage(&msg);}

DoEvents spends part of its time watching for other messages in thesame process. This behavior has no value in a preemptive-multitasking operatingsystem. Sleep yields more efficiently to other processes. Sleep is declaredas:

 Public Declare Sub Sleep Lib "kernel32" _	Alias "Sleep" (ByVal dwMilliseconds As Long)

and can be called as:

 Sleep 0&

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist