|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Waiting for a shell commandHi 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 Janus wrote:
Show quoteHide quote > Hi group, Launch the shell in a different thread. This allows your UI thread time > > 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 > to do it's own updating. Chris
Show quote
Hide quote
> Hugh Janus wrote: Thanks. How can I keep an eye on the thread waiting for it to> > 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 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.' this sounds good. could you help with how to do this? do you have an
example? thanks 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. |
|||||||||||||||||||||||