My ultimate goal is to get something like "ping.exe" to re-direct it's
standardOutput in real time to an .aspx page.
I've been able to get this behavior to work just fine in a regular
console application. I execute the process and the output is re-
directed to a windows textbox.
Below is the code I'm using to do that:
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click
executeTest()
End Sub
Public Sub executeTest()
Dim p As New System.Diagnost ics.Process()
p.StartInfo.Fil eName = "ping"
p.StartInfo.Arg uments = "www.yahoo. com"
p.StartInfo.Use ShellExecute = False
p.StartInfo.Red irectStandardOu tput = True
AddHandler p.OutputDataRec eived, AddressOf outputHandler
p.Start()
p.BeginOutputRe adLine()
p.Close()
Console.Write(" done")
End Sub
Public Delegate Sub AddTextCallback (ByVal strText As String)
Private Sub AddText(ByVal strText As String)
TextBox1.Text = TextBox1.Text & strText & Environment.New Line
End Sub
Private Sub outputHandler(B yVal sendingProcess As Object, _
ByVal outLine As System.Diagnost ics.DataReceive dEventArgs)
' Collect the sort command output.
If Not String.IsNullOr Empty(outLine.D ata) Then
Button1.Invoke( New AddTextCallback (AddressOf AddText), New
Object() {outLine.Data})
End If
End Sub
The key to code above for me was the "Button1.Invoke (...)" line.
On my .aspx page I have a webcontrol called "div1" that represents a
<div>. There is no such method called "Invoke" for this control.
Conceptually is there a way to invoke the delegate so that it runs in
the correct UI thread (whatever that thread is called)?
I've been reading like mad over the past few days about threads,
delegates, etc. so forgive my ignorance with terms etc. I've thought
also about creating a webservice to do this, but I'm not sure how to
return results in real time via the webservice. I can kick off the
process, but am not sure how to report the results back.