473,327 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Waiting for process end , how?

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
Aug 14 '06 #1
7 7253
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" <bd*****@sgiims.comschreef in bericht
news:uS**************@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

Aug 14 '06 #2
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

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:ev**************@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" <bd*****@sgiims.comschreef in bericht
news:uS**************@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


Aug 15 '06 #3

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]

Aug 15 '06 #4
Tom,

Exciting

:-)

Cor

"Tom Shelton" <to*@mtogden.comschreef in bericht
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]

Aug 15 '06 #5
Bob
Thanks Tom Gonna give it a try.
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]

Aug 15 '06 #6
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



"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]

Aug 15 '06 #7
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]

Aug 15 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matt Burland | last post by:
Hi, My app runs a DOS program as a process. Most of the time, given the right command line arguments, the DOS process runs by itself without needing any user intervention, but there is a certain...
39
by: jabailo | last post by:
I am looping through a text file, and with each row, I launch a web service, asynchronously. Before I move on to the next step in the process, I want to make sure that all the web services have...
5
by: bughunter | last post by:
Hi, Consider this code: ---- Monitor.Pulse(oLock); Monitor.Exit(oLock); ---- If a thread was waiting on oLock then will the current thread
4
by: Steve W | last post by:
Is it possible to keep some communication going between the browser and web server going while waiting for a long running process to finish ? We have one function on our app (ASP.NET / VB.NET)...
12
by: Raymond Lewallen | last post by:
How to wait for a process to stop completion is my goal. Obviously, the looping while waiting for the HasExited property is not a solution.. but thats the best I can come up off the top of my...
2
by: Bob | last post by:
I launch Word from within my application (Vs2005, VB) and I would like to make it necessary for the just opened Word to be closed before the rest of my code in the calling sub can execute. How can...
9
by: erikcw | last post by:
Hi, I have a cgi script where users are uploading large files for processing. I want to launch a subprocess to process the file so the user doesn't have to wait for the page to load. What is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.