Reputation: 20693
I can't see how Process.WaitForInputIdle() can return anything but true or throw an exception, but in documentation for that method is stated :
Return Value
Type: System.Boolean
true if the associated process has reached an idle state.
That if is confusing me, is that only documentation copy / paste from overloaded version of for method that have wait parameter or I am not understanding something ?
UPDATE
To clarify my question, I am aware how Process.WaitForInputIdle() works, just courious if it can returns false in some conditions.
Upvotes: 1
Views: 1200
Reputation: 941744
I think this might be an operating system compatibility problem. Not sure, I don't have reliable docs for Windows 98 anymore. The key issue is that it pinvokes the native winapi WaitForInputIdle() function, passing int.MaxValue (0x7ffffffff) instead of INFINITE (-1). So this call can actually time-out, after 24.85 days.
This restriction appears in more than one place, the System.Windows.Automation.Provider.WaitForInputIdle(int) method also specifies a maximum value of int.MaxValue.
So yes, if you get false then your program has been asleep for 25 days. Time to call it quits :)
Upvotes: 4
Reputation: 4768
If you supply the non overload you will wait indefinately until it becomes idle.
If you supply Process.WaitForInputIdle(0)
you basically are testing the process for idle.
If you supply Process.WaitForInputIdle(-1)
that is the same as the non overloaded version.
During UI start up there are lots of messages coming in. If you override WndProc in a test app you can see them flowing through.
EDIT: Seeing as you edited question.
If you Specify the WaitForInputIdle(0 or a non Infinite timeout) (ie testing) and the app isn't idle within that time then you would get a false afaik.
Upvotes: 0
Reputation: 8558
WaitForInputIdle()
simply calls WaitForInputIdle(int milliseconds)
, which in turn calls native WaitForInputIdle
implemented in User32.dll. The latter returns WAIT_TIMEOUT
if the wait was terminated because the time-out interval elapsed, which causes the .NET implementation to return false
.
EDIT: WaitForInputIdle()
passes 0x7fffffff to WaitForInputIdle(int milliseconds)
, which is not the same as INFINITE (defined as 0xffffffff in WinBase.h). Therefore if a process does not enter idle state in approximately 25 days, then WaitForInputIdle()
will return false.
Upvotes: 2