Page 1 of 1

RunProgram() #PB_Program_Ready

Posted: Sun Aug 28, 2016 12:20 pm
by IdeasVacuum
Add #PB_Program_Ready

When using RunProgram() to launch 'heavy' apps such as CAD-CAM, we need to know when that app has finished loading - typically they take a minute or two before they are ready.

Re: RunProgram() #PB_Program_Ready

Posted: Sun Aug 28, 2016 2:27 pm
by Keya
Would be super handy, but is it even possible and practical though?!? im thinking RunProgram (via standard API) loads and inits the PE/Mach/ELF structures of executable into memory, and creates the main thread (im guessing very close to this stage is where RunProgram typically returns control back to us) ... which might by nothing other than an immediate call to ExitProcess resulting in termination in a split second, or perhaps just loads simple window again in a split second, or perhaps five minutes of its own initialization code ... or perhaps we just happen to run the app at 11:59:59 and it would normally do nothing other than display a window, but at 12:00:00 its scheduled to automatically do a daily task of some sort (or for example if certain process parameters were used which affected the init), in which case we have an app which may or may not initialize immediately. Im pretty sure there are no for example #WM_IVE_FINISHED_INITIALIZING or whatever sent... if there were, i guess a good place to put one would be immediately before you enter your main message loop, but i've never seen anyone use it - guessing because there is none, and also it would require that the author of the other app remembered to even include the call.

So, therefore, with no NOTIFICATIONS being sent its way, wouldn't our PB app calling RunProgram have to do its own explicit thread CPU usage ACTIVE MONITORING? (i guess not overly difficult but certainly not just a matter of calling a single API, and could be tricky to do cross-OS!?). And even if we monitor the main thread, what if its message loop is poorly designed and sits on a constant ~5% cpu usage instead of expected ~0? It would be initialized, but in our monitors eyes still "initializing". Sorry if i've rained on your Sunday, im only wondering out loud though and hopefully i'm wrong :P

Re: RunProgram() #PB_Program_Ready

Posted: Mon Aug 29, 2016 8:32 am
by Dude
Here's an old thread that may help (it works for me): http://www.purebasic.fr/english/viewtop ... =7&t=38206

Re: RunProgram() #PB_Program_Ready

Posted: Mon Aug 29, 2016 1:35 pm
by Keya
WaitForInputIdle() could be a winner for some procs but it's still going to have some of the issues i mentioned though, and is Windows-only... and one of the comments in that thread said that Sleep(250) "seemed obsolete but i found it was still required" hrm :)