Home All Groups Group Topic Archive Search About

Waiting for process end , how?

Author
14 Aug 2006 8:14 PM
Bob
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

Author
14 Aug 2006 8:21 PM
Cor Ligthert [MVP]
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


Show quoteHide quote
"Bob" <bduf***@sgiims.com> schreef in bericht
news:uSv4E59vGHA.3392@TK2MSFTNGP04.phx.gbl...
> 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
>
Author
15 Aug 2006 2:54 PM
Bob
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



Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:ev8wQ89vGHA.4932@TK2MSFTNGP06.phx.gbl...
> 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" <bduf***@sgiims.com> schreef in bericht
> news:uSv4E59vGHA.3392@TK2MSFTNGP04.phx.gbl...
>> 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
>>
>
>
Author
15 Aug 2006 4:28 PM
Tom Shelton
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]
Author
15 Aug 2006 5:23 PM
Cor Ligthert [MVP]
Tom,

Exciting

:-)

Cor

Show quoteHide quote
"Tom Shelton" <t**@mtogden.com> schreef in bericht
news:1155659311.605212.36440@74g2000cwt.googlegroups.com...
>
> 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]
>
Author
15 Aug 2006 6:02 PM
Bob
Thanks Tom Gonna give it a try.
Bob
Show quoteHide quote
"Tom Shelton" <t**@mtogden.com> wrote in message
news:1155659311.605212.36440@74g2000cwt.googlegroups.com...
>
> 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]
>
Author
15 Aug 2006 7:34 PM
Bob
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









Show quoteHide quote
"Tom Shelton" <t**@mtogden.com> wrote in message
news:1155659311.605212.36440@74g2000cwt.googlegroups.com...
>
> 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]
>
Author
15 Aug 2006 8:46 PM
Tom Shelton
Bob wrote:
Show quoteHide quote
> 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]