0

在 Visual Studio 2012 中使用 VB。我不知道如何清除我需要清除的任何内容。

请参阅下面我使用的代码:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    If RichTextBox1.Text > "" Then
        pingProc.CancelOutputRead()
        'Need Clearing code here
        RichTextBox1.Text = ""
    End If
    Me.Height = 522

    With pingProc.StartInfo
        .FileName = "cmd.exe"
        .Arguments = "/c C:\Tracert.bat"
        .RedirectStandardInput = True
        .RedirectStandardOutput = True
        .UseShellExecute = False
        .CreateNoWindow = True
    End With

    AddHandler pingProc.OutputDataReceived, AddressOf HandleProcessOutput

    pingProc.Start()
    pingProc.BeginOutputReadLine()

End Sub

Private Sub HandleProcessOutput(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs)
    Me.Invoke(New DelegateAddText(AddressOf AddText), New Object() {e.Data})
End Sub

Delegate Sub DelegateAddText(ByVal Text As String)
Private Sub AddText(ByVal Text As String)
    RichTextBox1.Text &= Text & vbCrLf
End Sub

现在,当我运行此代码时,它运行良好。但我将不得不运行它第二次或更多次。当我这样做时,我最终会得到两倍或更多的副本,具体取决于我运行此代码的次数。

首轮:

Performing Trace Route to 198.224.169.244
Tracing route to 244.sub-198-224-169.myvzw.com [198.224.169.244]
over a maximum of 30 hops:

第二次运行:

Performing Trace Route to 198.224.169.244
Performing Trace Route to 198.224.169.244
Tracing route to 244.sub-198-224-169.myvzw.com [198.224.169.244]
Tracing route to 244.sub-198-224-169.myvzw.com [198.224.169.244]
over a maximum of 30 hops:
over a maximum of 30 hops:
4

1 回答 1

0

可能是由Addhandler...引起的,所以,你可以试试这个..

Dim Handled As Boolean

If Not Handled Then 
  AddHandler pingProc.OutputDataReceived, AddressOf HandleProcessOutput
  Handled = True
End If
于 2013-07-24T08:00:38.377 回答