Home All Groups Group Topic Archive Search About

To catch when a process is terminated

Author
13 Jun 2006 8:28 AM
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

Author
13 Jun 2006 10:13 AM
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.




Show quoteHide quote
"andreas" <andr***@pandora.be> wrote in message
news:lGujg.479669$%V4.12409968@phobos.telenet-ops.be...
> 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
>
>
Author
13 Jun 2006 1:49 PM
Herfried K. Wagner [MVP]
"andreas" <andr***@pandora.be> schrieb:
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>