To catch when a process is terminated

A

andreas

Hi,
In my code I have the following
System.diagnostics.process.start("wordpad",sFileN)
And this is follow bij others codelines
It seems that these other lines are executed before the process is
terminated by closing this process but I don't want that.
Can I write something like ?

If ........ then
than the other lines
end if

Where ...... is the code that I want to know for knowing that the process is
terminated.
Thanks for any response
 
R

RMT

Start will tell Windoze to spawn another process within which Wordpad
executes - just like you launched it from the Start menu or something. So
the command will return with a success/failure, ie. succedded in starting or
failed to start - what happens next is in your code, but Wordpad is up and
running. If you were using automation then that would be a different
matter - you could control the startup, edit and shutdown process.

The only real way to know when the process closes is to check sFileN, to see
if it's in use - as long as it is in use, you can assume wordpad has control
of it. You can use a timer to do this, trying to open sFileN and catching
any IO exception ("file in use") you get as a result.
 
H

Herfried K. Wagner [MVP]

andreas said:
In my code I have the following
System.diagnostics.process.start("wordpad",sFileN)
And this is follow bij others codelines
It seems that these other lines are executed before the process is
terminated by closing this process but I don't want that.

\\\
Dim p As Process = Process.Start(...)
p.WaitForExit()
///

.... or set the 'Process' object's 'EnableRaisingEvents' property to 'True'
and handle its 'Exited' event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top