Theading/Updating UI ?

N

n

Hi all,

Got a niggly problem, that I can't seem to crack.
I have a command line process, which I started and capture the
standardoutput with, and I need to update a form with some of the output as
it progresses. But I can't update the form from the Sub OutputHandler2.

Below is my code, any help appreciated.


AddHandler MyProc.OutputDataReceived, AddressOf Me.OutputHandler2
MyProc.StartInfo.UseShellExecute = False
MyProc.StartInfo.ErrorDialog = False
MyProc.StartInfo.CreateNoWindow = True
MyProc.StartInfo.RedirectStandardError = False
MyProc.StartInfo.RedirectStandardOutput = True
MyProc.StartInfo.FileName = process
MyProc.StartInfo.Arguments = param

MyProc.Start()
MyProc.BeginOutputReadLine()
MyProc.WaitForExit()
MyProc.CancelOutputRead()


Sub OutputHandler2(ByVal sendingProcess As Object, ByVal outLine As
DataReceivedEventArgs)

cmdOutput = ""

If Not String.IsNullOrEmpty(outLine.Data) Then
cmdOutput = outLine.Data

' does some uninteresting STUFF here
' NEED TO UPDATE a FORM HERE

End If

End Sub
 
K

Khaled Hussein

Updating the UI, usually has to be done using Invoke method.
Invoke (UpdateUI);
where you build this function UpdateUI(), and put all the form updating
stuff into it.

I hope this helps
Khaled Hussein
 
J

Jon Skeet [C# MVP]

n said:
Got a niggly problem, that I can't seem to crack.
I have a command line process, which I started and capture the
standardoutput with, and I need to update a form with some of the output as
it progresses. But I can't update the form from the Sub OutputHandler2.

You need to use Control.Invoke/BeginInvoke to make the call on the UI
thread.

See http://www.pobox.com/~skeet/csharp/threads/winforms.shtml

(The code is in C#, but the principles are equally applicable in
VB.NET.)
 

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