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" <to*@mtogden.comwrote in message
news:11*********************@74g2000cwt.googlegrou ps.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]