Please review the below code:
Imports System.Diagnostics Imports System.Threading Public Class Form1 Dim pingProc As New Process Dim pingThread As New Thread(AddressOf pingProc.Start) Private Sub btnPing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPing.Click With pingProc.StartInfo .FileName = "ping.exe" .UseShellExecute = False .RedirectStandardOutput = True .RedirectStandardInput = True .CreateNoWindow = True If cbNumOfTimes.Text = "Continuous" Then .Arguments = Me.tbHost.Text & " " & "-t" Else Select Case cbNumOfTimes.Text Case "10" .Arguments = Me.tbHost.Text & " " & "-n 10" Case "20" .Arguments = Me.tbHost.Text & " " & "-n 20" Case "50" .Arguments = Me.tbHost.Text & " " & "-n 50" Case "100" .Arguments = Me.tbHost.Text & " " & "-n 100" End Select End If End With If cbNumOfTimes.Text = "Contiuous" Then pingThread.Start() Else pingProc.Start() btnStop.Enabled = False Me.tbResult.Text = pingProc.StandardOutput.ReadToEnd End If End Sub Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click pingThread.Abort() Me.tbResult.Text = pingProc.StandardOutput.ReadToEnd End Sub End Class
What I want to do is to let user click on stop button to stop the ping process if the ping process is continuous.
I realised a need to do multithreading in order to stop the continuous ping process.
However I wrote the above code and realised the ping process is continuing and i cannot click on any button, my application seems like hang, which means i might have used the multi-threading incorrectly.
Hope to get some suggestions and guidance. Thanks.

New Topic/Question
Reply




MultiQuote






|