none
How does the Process.WaitForInputIdle method determine whether a process has a graphical interface and a message loop? RRS feed

  • Question

  • I see the documentation says: "If the process has no message loop, WaitForInputIdle () throws InvalidOperationException" I use this method to wait for a java program. When using javaw.exe to start, it can return normally, but when using java.exe to start, it will report an error: the process may not have a graphical interface. As far as I know, the biggest difference between java and javaw is that java is associated with a console window.

    Can you give me some tips?

    Monday, March 30, 2020 3:41 AM

Answers

All replies

  • Hi Adam_Jin,

    Thank you for posting here.

    Generally, GUI application uses javaw.exe, and console application uses java.exe, so you cannot use java.exe to start the method.

    Can one executable be both a console and GUI application?

    To check if a process has a graphical interface, you can look at Process.MainWindowHandle Property.

    Here's a reference you can refer to:

    How can I tell if a process has a graphical interface?

    Hope it can help you.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 30, 2020 6:35 AM
    Moderator
  • The Process.WaitForInputIdle() calls WaitForInputIdle() Windows API internally.

    It throws InvalidOperation exception is the function result is neither success nor timeout.

    The Windows API documentation specified "If this process is a console application or does not have a message queue, WaitForInputIdle returns immediately."

    Note that Process.MainWindowHandle will also return 0 is Main window is hidden or not visible on taskbar.

    As for how Windows knows whether it has message loop, the simplest answer is that the system keeps track of it. Otherwise it won't be able to let you send boardcast messages.
    • Edited by cheong00Editor Tuesday, March 31, 2020 2:46 AM
    • Marked as answer by Adam_Jin Thursday, April 9, 2020 7:51 AM
    Tuesday, March 31, 2020 2:45 AM
    Answerer
  • Hi Adam_Jin,

    Did you solve your problem? If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, April 8, 2020 7:19 AM
    Moderator