Detecting when a process is idle
-
I am writing an application to do some batch processing. Basically it uses CreateProcess() to create a processes (with the desired command line arguments) over and over a number of times. Each run produces a text file which i will compile together. My problem however is that the process i am executing will perform its job and NOT close. If i call CreateProcess() while the application is still opened it ignores my arguments and does nothing, so i need to close between each execution. Can anybody offer any suggestions as to how to detect when the process has completed the work. I am confident that i can tell it to close, im just not sure how to determine when. The processing time is unpredictable. The cpu is used intensively during the operation. I attempted using the ForegroundIdleProc() hook function to flag me when the foreground thread went idle, however this does not seem to work (the function is hooked ok, as it is called when i close the app as well as scroll around in the app, it just doesnt call it when i want it to!). Any suggestions would be greatly appreciated. Alex Deem
-
I am writing an application to do some batch processing. Basically it uses CreateProcess() to create a processes (with the desired command line arguments) over and over a number of times. Each run produces a text file which i will compile together. My problem however is that the process i am executing will perform its job and NOT close. If i call CreateProcess() while the application is still opened it ignores my arguments and does nothing, so i need to close between each execution. Can anybody offer any suggestions as to how to detect when the process has completed the work. I am confident that i can tell it to close, im just not sure how to determine when. The processing time is unpredictable. The cpu is used intensively during the operation. I attempted using the ForegroundIdleProc() hook function to flag me when the foreground thread went idle, however this does not seem to work (the function is hooked ok, as it is called when i close the app as well as scroll around in the app, it just doesnt call it when i want it to!). Any suggestions would be greatly appreciated. Alex Deem
Call
WaitForSingleObject()
on the process handle:STARTUPINFO si = {sizeof(STARTUPINFO)};
PROCESS_INFORMATION pi;if ( CreateProcess(..., &si, &pi) )
{
WaitForSingleObject ( pi.hProcess, INFINITE );
CloseHandle ( pi.hProcess );
CloseHandle ( pi.hThread );
}Your thread will block in the Wait call until the child process exits. --Mike-- http://home.inreach.com/mdunn/ You are the weakest link, GOODBYE!
-
Call
WaitForSingleObject()
on the process handle:STARTUPINFO si = {sizeof(STARTUPINFO)};
PROCESS_INFORMATION pi;if ( CreateProcess(..., &si, &pi) )
{
WaitForSingleObject ( pi.hProcess, INFINITE );
CloseHandle ( pi.hProcess );
CloseHandle ( pi.hThread );
}Your thread will block in the Wait call until the child process exits. --Mike-- http://home.inreach.com/mdunn/ You are the weakest link, GOODBYE!
I believe u misunderstood me. The child process does NOT exit. After doing the processing it sits there displaying the results in its UI. (The child app is a 3rd party app, so i have no control over this). I wish to determine how to detect when the app is sitting there idle, so i can then kill it. Alex Deem
-
I believe u misunderstood me. The child process does NOT exit. After doing the processing it sits there displaying the results in its UI. (The child app is a 3rd party app, so i have no control over this). I wish to determine how to detect when the app is sitting there idle, so i can then kill it. Alex Deem
Use WaitForInputIdle. Tomasz Sowinski -- http://www.shooltz.com