Search code examples
delphilistboxpid

Delphi 2010 - does PID exists? If Yes then show PID in listbox else remove PID from listbox


I'm working on an application that is running multiple external programs at once. After creating the process, I store each title of the process, the PID number and the handle inside a list box. While process exists i want to show it in that list box. If the process is ended i want the list box to automatically remove the reference. Any idea?

Thank you


Solution

  • I finally did it! If any one else is looking for an answer here is what i did:

    • I allow users to select multiple files for processing and display them in the first listbox
    • for each listbox item, I create a process that contains the unique name of the file and move the name of the file that is being processed in the second listbox. This is done by using a timer that cycles the whole listbox. After creating the process, i move the filename from listbox1 to listbox2
    • using a function I got the handle for the process that I just created. For each file, I store the filename,PID and handle in the second listbox.
    • I use the second timer that ticks at 1000ms to cycle threw all listbox2 items and compare processhandle with existing process list.If process exits then do nothing, else remove listbox2 item by string.

    This trick does not require threads. I tested this with 100 files that created 100 unique process. I hope I managed to help anyone who is looking for a solution like I did.