Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Waiting for process end , how?

93 views
Skip to first unread message

Bob

unread,
Aug 14, 2006, 4:14:36 PM8/14/06
to
Process.start("Mydoc.doc") starts Word with the file. I need to wait for
Word to be closed before more code can execute in my app. How can I do this?

Thanks for any help
Bob


Cor Ligthert [MVP]

unread,
Aug 14, 2006, 4:21:36 PM8/14/06
to
Bob,

How about to use the wait for exit in the process class to wait on the exit
of that process.

:-)

http://msdn2.microsoft.com/en-us/library/fb4aw7b8.aspx

I hope this helps,

Cor


"Bob" <bdu...@sgiims.com> schreef in bericht
news:uSv4E59v...@TK2MSFTNGP04.phx.gbl...

Bob

unread,
Aug 15, 2006, 10:54:23 AM8/15/06
to
I been trying to do that with the following code
Dim pr As Process

pr.Start(Fname) where Fname is the filename to use with the process.

However I get a message in the IDE saying that Access of Shared member,
constant member.... etc. qualifying expression will not be evaluated.

Got any code snippets to do this? It seems straightforward but <GGGG> :-)

Thanks for your help.

Bob

"Cor Ligthert [MVP]" <notmyfi...@planet.nl> wrote in message
news:ev8wQ89v...@TK2MSFTNGP06.phx.gbl...

Tom Shelton

unread,
Aug 15, 2006, 12:28:31 PM8/15/06
to

Bob wrote:
> I been trying to do that with the following code
> Dim pr As Process
>
> pr.Start(Fname) where Fname is the filename to use with the process.
>
> However I get a message in the IDE saying that Access of Shared member,
> constant member.... etc. qualifying expression will not be evaluated.
>
> Got any code snippets to do this? It seems straightforward but <GGGG> :-)
>
> Thanks for your help.
>
> Bob

Bob - here is a simple console application that demonstrates this
method:

Option Explicit On
Option Strict On

Imports System
Imports System.Diagnostics

Module Module1

Public Sub Main()
Dim p As Process = Process.Start("notepad.exe")
p.WaitForExit()
Console.WriteLine("Done")
End Sub

End Module


This is a blocking operation... Another way to do this, whithout
blocking would be:

Option Explicit On
Option Strict On

Imports System
Imports System.Threading
Imports System.Diagnostics

Module Module1
Private WithEvents p As New Process
Private exited As Boolean = False

Public Sub Main()
p.EnableRaisingEvents = True
p.StartInfo.FileName = "notepad.exe"
p.Start()

While Not exited
Thread.Sleep(1000)
Console.WriteLine("Running!")
End While

Console.WriteLine("Done")
End Sub

Private Sub NotepadExited(ByVal sender As Object, ByVal e As
EventArgs) Handles p.Exited
exited = True
End Sub

End Module

Anwyay - HTH,

--
Tom Shelton [MVP]

Cor Ligthert [MVP]

unread,
Aug 15, 2006, 1:23:25 PM8/15/06
to
Tom,

Exciting

:-)

Cor

"Tom Shelton" <t...@mtogden.com> schreef in bericht
news:1155659311....@74g2000cwt.googlegroups.com...

Bob

unread,
Aug 15, 2006, 2:02:13 PM8/15/06
to
Thanks Tom Gonna give it a try.
Bob
"Tom Shelton" <t...@mtogden.com> wrote in message
news:1155659311....@74g2000cwt.googlegroups.com...

Bob

unread,
Aug 15, 2006, 3:34:44 PM8/15/06
to
Thanks Tom,
Excellent info for me.
I've been testing the first snippet of code using Word instead of Notepad
Dim pr As Process = Process.Start("Mydoc.doc") 'Starts Word and opens the
file OK
pr.WaitForExit()
Console.WriteLine("Done")
However when execution hits the line p.WaitForExit() I get an unhandled
exception Object not set to an instance of an object. Normally this means
that I did not instantiate the pr object and indeed the code does not do
that (it would need the New keyword in he declaration) however with this
shared class you can not use the new keyword in the declaration.

How could I end up gettng Word to open up and have to wait before going back
to my application form that the process is closed. I look at the docs and I
see that Waitforexit does interrupt the calling thread and this is indeed
whats needed. I just don't see how to code it.

Any help is really, really appreciated.

Bob

"Tom Shelton" <t...@mtogden.com> wrote in message
news:1155659311....@74g2000cwt.googlegroups.com...
>

Tom Shelton

unread,
Aug 15, 2006, 4:46:07 PM8/15/06
to
Bob wrote:
> Thanks Tom,
> Excellent info for me.
> I've been testing the first snippet of code using Word instead of Notepad
> Dim pr As Process = Process.Start("Mydoc.doc") 'Starts Word and opens the
> file OK
> pr.WaitForExit()
> Console.WriteLine("Done")
> However when execution hits the line p.WaitForExit() I get an unhandled
> exception Object not set to an instance of an object. Normally this means
> that I did not instantiate the pr object and indeed the code does not do
> that (it would need the New keyword in he declaration) however with this
> shared class you can not use the new keyword in the declaration.
>
> How could I end up gettng Word to open up and have to wait before going back
> to my application form that the process is closed. I look at the docs and I
> see that Waitforexit does interrupt the calling thread and this is indeed
> whats needed. I just don't see how to code it.
>
> Any help is really, really appreciated.
>
> Bob


Bob - the example I wrote works fine for me... With word as well. I
just tested it here with word to be certain.

The call to process.start returns an instance of the process class, so
there is no shared methods involved. You do not call this on the
Process class, but on the instance returned by the Process.Start
method.

I think what we need is the shortest snippet of ACTUAL code that
demonstrates the issue, since I can not replicate this problem.

--
Tom Shelton [MVP]

0 new messages