Waiting for a shell command

  • Thread starter Thread starter Hugh Janus
  • Start date Start date
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
 
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
 
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?
 
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.'
 
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
 
My problem was a stupid mistake on my part. The code I posted should
work correctly.
 
Back
Top