I am using Borland C++ builder to create an application that will do the following:
Launch another program in execution (with CreateProcess()) and suspend the program flow until the launched program has finished executing. However, I don't want all flow to stop executing, just everything besides the GUI. If I use WaitForSingleObject(), the GUI also freezes until the program has finished. I want to be able to press a "stop" button that will instantly terminate the launched process. For this, I have the following, admittedly hackish solution:
Use _beginthread() to launch the function that does the program execution, have a variable done that is initially zero, then have a loop in the function that used _beginthread() : while (!done) Application->ProcessMessages; done will be set to 1 once the thread finishes.
This fixes the problem, at least for fast computers. On slower computers (not really slow, 2.0ghz P4 slow) not only does this also freeze the interface, it also makes the launched program run incredibly slow, making the whole thing freeze for a long time.
So, I'm open to any suggestions. How can I execute the program, suspend a certain function's execution until it finishes, keep the GUI responsive and now slow everything down?