WaitForInputIdle

2ourc3 0 Reputation points
2024-03-22T11:18:49.5166667+00:00

Hi everyone,

I'm working on a Windows C++ application where I need to wait for a multi-threaded process to finish processing its initial. I'm aware that WaitForInputIdle from winuser.h only waits for one thread in the target process to be idle, which isn't ideal for my scenario.

I'm looking for recommendations on alternative approaches or function to achieve this. Could you share your insights on the best approach for this scenario ?

Thanks in advance for your help!

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,612 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,722 questions
{count} votes

2 answers

Sort by: Most helpful
  1. RLWA32 45,476 Reputation points
    2024-03-22T11:30:16.0566667+00:00

    One alternative would be for the parent application to wait for an event to be signaled by the multi-threaded child process when it has finished its initialization. The parent could use the MsgWaitForMultipleObjectsEx function to pump messages while waiting for the event to avoid making its UI unresponsive.

    0 comments No comments

  2. 2ourc3 0 Reputation points
    2024-03-22T14:58:23.58+00:00

    Thank you all for your answers. Apologies I didn't provided enough information in my initial post.

    My goal is that the parent application launch an other application as a process, for example notepad.exe. Then once the remote process has finished processing the file input and is Idle, perform certain actions, for example close the remote process.

    If the remote process was a single-thread application then the WaitForInputIdle function would be sufficient but not for multi-threaded one


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.