RunProgram() #PB_Program_Ready

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

RunProgram() #PB_Program_Ready

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: RunProgram() #PB_Program_Ready

Post 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
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: RunProgram() #PB_Program_Ready

Post by Dude »

Here's an old thread that may help (it works for me): http://www.purebasic.fr/english/viewtop ... =7&t=38206
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: RunProgram() #PB_Program_Ready

Post 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 :)
Post Reply