How much time does the WinExec function wait for?

Although the WinExec is not recommended at MSDN for the current Windows platforms, many people including me still use this function due to its simplicity.

In most cases, it works well and extremly easy to use.
However, it occasionally makes your application hang. This is because the function WinExec does not return until created program calls GetMessage.

This is stated on the remark section of the function as following.

The WinExec function returns when the started process calls the GetMessage function or a time-out limit is reached. To avoid waiting for the time out delay, call the GetMessage function as soon as possible in any process started by a call to WinExec.

To see it, click the link: http://msdn.microsoft.com/en-us/library/windows/desktop/ms687393(v=vs.85).aspx


Most developers know that the function waits for something. However, it is not well known how much time it sleeps exactly.

Before I investigate it, I assumed the time is not that long, at most 5 seconds or 3 seconds.

However, the truth is shown in the below screenshot.


Surprisingly, the waiting time is 30 seconds!!
Since it is too huge, if an application is screwed with this function, it looks like it is hangged.

Therefore, you should know it waits for such a long time when you are using this function!

Trackback 0 Comment 0