Kill process if it takes too long to complete
Posted on 2005-04-24
I have a program (A) which creates an instance of another program via GetObject (B). Then using the created (or found) object (B) from GetObject, I attempt to use VB to open a file in the newly created instance (B) and manipulate the file. Sometimes however, program (B) will stop responding due to any number of reasons that I am aware of, for example the file has embedded macros and program (B) pops up a window the user if they want to enable macros, or the file is corrupted and cannot be opened, or the file type is incorrect and cannot be opened. In each of these instances, program (B) pops up a window and waits for user interaction. I need program (A) to wait for a specified time, perhaps via a timer, and if the timer fires, close the current process and start a new one. The problem I have encountered is that the timer in a VB form evidently ceases to function or rather it pauses while it is waiting on the return value from the OLE interaction.
So, how can I kill a process (program B) if it is simply waiting for user input, from a timer in (program A).
I used this code in the timer
SendMessage Obj.hWnd, WM_DESTROY
but evidently the timer never fires while it is waiting on the other application to complete, even though it is enabled and set to a relatively short time frame.