al momento de ejecutar la app se marca error en la linea txtResults.Text = SR.ReadToEnd.
1. Cuando tengas un error, por favor da los detalles necesarios para poder ayudarte.
El mensaje exacto de error que te indica el debugger de VisualStudio. ya que de lo contrario estamos haciendo el paripé sin tener información precisa.
Sea cual sea el error que te indique imagino que es porque estás intentando modificar un control desde un Thread distinto al Thread donde creaste el cotnrol. es decir, tienes el control
txtResults en el thread "X" e intentas modificarlo desde el thread "Y", no puedes modificar un control así como así desde otro thread, primero debes comprobar si el control necesita ser invocado, y después, invocarlo.
Ejemplo:
Imports System.Threading.Tasks
Public Class Form1
''' <summary>
''' The CMD <see cref="System.Diagnostics.Process"/> instance.
''' </summary>
Private WithEvents cmdProcess As New Process With
{
.EnableRaisingEvents = True,
.StartInfo = New ProcessStartInfo With
{
.FileName = "cmd.exe",
.Arguments = String.Empty,
.RedirectStandardInput = False,
.RedirectStandardOutput = True,
.RedirectStandardError = True,
.UseShellExecute = False,
.CreateNoWindow = True
}
}
''' <summary>
''' Gets the ping commandline arguments.
''' </summary>
Private ReadOnly Property PingArguments As String
Get
Return String.Format("ping.exe ""{0}.{1}.{2}.{3}""",
TextBox1.Text, TextBox2.Text,
TextBox3.Text, TextBox4.Text)
End Get
End Property
Private Sub btnSend_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles btnsend.Click
Task.Factory.StartNew(AddressOf CMDAutomate)
End Sub
Private Sub CMDAutomate()
With Me.cmdProcess
.StartInfo.Arguments = String.Format("/C ""{0}""", Me.PingArguments)
.Start()
.BeginOutputReadLine()
.BeginErrorReadLine()
.WaitForExit()
End With
End Sub
''' <summary>
''' Occurs when an application writes to its redirected <see cref="System.Diagnostics.Process.StandardOutput"/> stream.
''' Occurs when an application writes to its redirected <see cref="System.Diagnostics.Process.StandardError"/> stream.
''' </summary>
Private Sub cmdProcess_OutputDataReceived(ByVal sender As Object, ByVal e As DataReceivedEventArgs) _
Handles cmdProcess.OutputDataReceived,
cmdProcess.ErrorDataReceived
Select Case txtResults.InvokeRequired
Case True
txtResults.Invoke(Sub() txtResults.AppendText("" & e.Data))
txtResults.Invoke(Sub() txtResults.AppendText(Environment.NewLine))
Case Else
txtResults.AppendText(e.Data)
txtResults.AppendText(Environment.NewLine)
End Select
' Debug.WriteLine(e.Data)
#End If
End Sub
''' <summary>
''' Occurs when a <see cref="System.Diagnostics.Process"/> exits.
''' </summary>
Private Sub cmdProcess_Exited(ByVal sender As Object, ByVal e As EventArgs) _
Handles cmdProcess.Exited
Debug.
WriteLine(String.
Format("cmdProcess has exited with exit code: {0}",
DirectCast(sender, Process).ExitCode))
End Sub
End Class
Saludos