2) Now if I terminate the external program using the program's usual exit, is there some state of the useExe obect I can use to detect that termination?
predicates
wait :().
wait :(unsigned Milliseconds= multiThread_native::infinite_timeout)-> unsigned EventCode.
% @short Suspends thread's execution until the object state to become signaled or time interval to elapse.% @detail The thread enters the wait state. The return value #EventCode specifies one of the following:<br>% multiThread_native::wait_abandoned - only for mutex synchronization object: mutex was not released before the owning thread terminated.% The ownership of mutex is granted to the calling thread, and the mutex is set to nonsignaled. <br>% multiThread_native::wait_object_0 - the state of synchronization object is signaled.<br>% multiThread_native::wait_timeout - the time interval Milliseconds elapsed, and the object stayed in nonsignaled state.<br>% @exception nativeCallException is raised if internal API function call failed% @endpredicates
tryWait :(unsigned Milliseconds)determ.
% @short Succeeds if the state becomes signaled before the timeout #Milliseconds (default infinite wait) expires.% @exception nativeCallException is raised if internal API function call failed% @end
To "poll" rather than doing a blocking wait you should use tryWait.
Thanks, and I am encouraged but confused.
I don't know what it means to be "signaled" or "unsignaled".
I have drilled into the syncObject created by useExe and closely examined the "wait" type functions with the debug. However, I do not see a way the calling obect ("form.frm") receives an event or notice that can trigger an action. (I have tried many combination of wait(), wait(Millisecs) and trywait()).
In some cases programs simply launch other programs and then exit. Our IDE for example examines if there is already an IDE with the same project open, if that is the case the it puts focus to that IDE and exits.
Likewise, Notepad++ (controlled by a setting) will switch to an already opened.
If you have Notepad++ installed you can try this little program:
implement main
open core, stdio
clauses
run():-E= useExe::new(@"C:\Program Files\Notepad++\notepad++.exe"),E:run(),foreach_= std::cIterate(10)do
multiThread_native::sleep(100),
writef("%\n", toBoolean(E:isActive()))end foreach.
end implement main
goal
console::runUtf8(main::run).
With and without Notepad++ already running.
Regarding "signaled". There are a number of syncObjects: mutex, criticalSection, event ... and useExe. Signalled means something different for each of these. For useExe it means terminated.