R
ryan1234
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(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
executeTest()
End Sub
Public Sub executeTest()
Dim p As New System.Diagnostics.Process()
p.StartInfo.FileName = "ping"
p.StartInfo.Arguments = "www.yahoo.com"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
AddHandler p.OutputDataReceived, AddressOf outputHandler
p.Start()
p.BeginOutputReadLine()
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.NewLine
End Sub
Private Sub outputHandler(ByVal sendingProcess As Object, _
ByVal outLine As System.Diagnostics.DataReceivedEventArgs)
' Collect the sort command output.
If Not String.IsNullOrEmpty(outLine.Data) 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.
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(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
executeTest()
End Sub
Public Sub executeTest()
Dim p As New System.Diagnostics.Process()
p.StartInfo.FileName = "ping"
p.StartInfo.Arguments = "www.yahoo.com"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
AddHandler p.OutputDataReceived, AddressOf outputHandler
p.Start()
p.BeginOutputReadLine()
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.NewLine
End Sub
Private Sub outputHandler(ByVal sendingProcess As Object, _
ByVal outLine As System.Diagnostics.DataReceivedEventArgs)
' Collect the sort command output.
If Not String.IsNullOrEmpty(outLine.Data) 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.