|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Theading/Updating UI ?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 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 Show quote "n" <n@n.com> wrote in message news:%23pg36cXVGHA.4384@tk2msftngp13.phx.gbl... > 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 > > > n <n@n.com> wrote:
> Got a niggly problem, that I can't seem to crack. You need to use Control.Invoke/BeginInvoke to make the call on the UI > 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. 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.) -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too |
|||||||||||||||||||||||