Hi i got a thread that goes like that.
VB Code:
dim thrd as System.Threading.Thread thrd = New Threading.Thread(AddressOf ReceiveDataLoop) running = True thrd.Start() End Sub Private Sub ReceiveDataLoop() While (running) receiveData() Thread.Sleep(500) End While End Sub
when i want to abort the thread it will hang at the .abort method why is it so? how do i solve it?
VB Code:
' the thread called method Public Sub receiveData() Dim statusck As Integer networkStream = tcpClient.GetStream() Dim bytes(tcpClient.ReceiveBufferSize) As Byte If networkStream.CanRead = True Then networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize)) Dim returndata As String = Encoding.ASCII.GetString(bytes, 0, bytes.Length) If (returndata.ToString <> "") Then If (returndata.ToString = 9) Then Me.WindowState = FormWindowState.Minimized Me.NotifyIcon1.Visible = True EnableLowLevelKeys(True) ElseIf (returndata.ToString = 1) Then Me.WindowState = FormWindowState.Maximized Me.NotifyIcon1.Visible = False Me.Visible = True Me.Show() EnableLowLevelKeys(False) ElseIf (returndata.ToString = 0) Then stopWhile() MsgBox(running) Disconnect() Me.NotifyIcon1.Visible = False MsgBox("I am here 1") thrd.Abort() ' always hang here MsgBox("I am here 2") Application.Exit() End If End If End If networkStream.Flush() End Sub




Reply With Quote