I want to perform a function (set the thread priority) for a particular process thread but I need to wait for that process to appear before doing so, then I'll get the process ID. After getting the process ID I will then set the thread priority.
What is the most reliable and best way to wait for that process to appear?
I already know how to get the PID, I just need a good way to wait for it. I know I probably need to do some type of loop or something, but whats the best way to do that? Wait, Until, etc....? I really need it to be very light on CPU time and very small memory foot print wise.
Best way to wait for a process to appear?
Re: Best way to wait for a process to appear?
Are you launching the process yourself, or is it a third-party app?
If yourself, then for Windows (not Linux/Mac) I've been using this:
Note: The Sleep_(250) seems to be obsolete, but in my tests it's needed,
just to give the launched app a quarter of a second longer to get ready
than it reports. That is: without it, the text doesn't always go to Notepad.
If yourself, then for Windows (not Linux/Mac) I've been using this:
Code: Select all
Procedure RunAndWaitTillReady(exe$)
exe=RunProgram(exe$,"",GetPathPart(exe$))
If exe : WaitForInputIdle_(exe,#INFINITE) : Sleep_(250) : EndIf
EndProcedure
RunAndWaitTillReady("notepad.exe")
keybd_event_(#VK_O,0,0,0) : keybd_event_(#VK_O,0,#KEYEVENTF_KEYUP,0)
keybd_event_(#VK_K,0,0,0) : keybd_event_(#VK_K,0,#KEYEVENTF_KEYUP,0)
just to give the launched app a quarter of a second longer to get ready
than it reports. That is: without it, the text doesn't always go to Notepad.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.