views:

135

answers:

2

I'm using a 3rd party assembly to do some processing, and it spawns 2 child processes to perform some work. I'm running this in a separate thread.

I want to be able to cancel the processing if it runs for too long - my problem is that if I abort the thread the spawned processes are still running.

Is there a way to determine what processes were spawned by a specific thread so I can kill them?

I can perform the work in a separate Appdomain if that would help any - is there a way to determine what processes were spawned within a specific Appdomain?

Notes

  • I have no way of getting the process IDs from the 3rd party assembly
  • I cannot simply kill all processes matching a name, as I will be running a few of these worker threads concurrently (and if one runs too long I only want to kill the processes spawned in that thread)
  • I know it's 'safe' for me to just kill these processes
+1  A: 

If the third party assembly doesn't provide you a callback or some way to determine that a process is spawned with a given PID so that you can keep track of them, there's no way to find out that a process has been spawned from a given thread in your application. The closest you might get is the command line used to run the process.

Darin Dimitrov
No, there are no callbacks.I could use the command line used to run the process, but as in the 'notes' section of my question, that would kill all processes with that name - I only want to kill processes for a single thread at a time.
Cocowalla
+1  A: 

I figured out a workaround - when a worker thread is aborted the processes it has spawned are 'orphaned' (the parent process ID is no longer than of my application), so I can determine which processes to kill that way.

Cocowalla