Waiting for a shell command

H

Hugh Janus

Hi group,

I am executing a shell command that calls a .BAT file. I have to wait
for this batch file to finish so I use the wait = true parameter in the
shell command. However, this means that my app freezes causing the
form is not be refreshed when something goes in front of it and then
disappears. This looks ugly and gives the impression that the program
has crashed.

Any ideas how I can repaint my screen whilst waiting for the shell
command to finish?

Thanks
 
C

Chris

Hugh said:
Hi group,

I am executing a shell command that calls a .BAT file. I have to wait
for this batch file to finish so I use the wait = true parameter in the
shell command. However, this means that my app freezes causing the
form is not be refreshed when something goes in front of it and then
disappears. This looks ugly and gives the impression that the program
has crashed.

Any ideas how I can repaint my screen whilst waiting for the shell
command to finish?

Thanks

Launch the shell in a different thread. This allows your UI thread time
to do it's own updating.

Chris
 
H

Hugh Janus

Hugh said:
Launch the shell in a different thread. This allows your UI thread time
to do it's own updating.

Chris

Thanks. How can I keep an eye on the thread waiting for it to
terminate?
 
C

Chris Dunaway

Start the process, but don't wait for it to finish. Instead, subscribe
to its Exited event. That event will fire when the process exits.'
 
H

Hugh Janus

this sounds good. could you help with how to do this? do you have an
example?

thanks
 
C

Chris Dunaway

Here is a small example, however, it seems to raise the Exited event
when the process has started. Not sure if I'm missing something or
not. Try it and see what your results are.

Private p As New System.Diagnostics.Process

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim pi As New ProcessStartInfo("c:\windows\notepad.exe")

p.StartInfo = pi
p.EnableRaisingEvents = True

AddHandler p.Exited, AddressOf ProcessComplete

p.Start()
End Sub

Private Sub ProcessComplete(ByVal sender As Object, ByVal e As
System.EventArgs)
MsgBox("Process has exited!")
End Sub
 
C

Chris Dunaway

My problem was a stupid mistake on my part. The code I posted should
work correctly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top