Hi i got a thread that goes like that.

VB Code:
  1. dim thrd as System.Threading.Thread
  2. thrd = New Threading.Thread(AddressOf ReceiveDataLoop)
  3.         running = True
  4.         thrd.Start()
  5.     End Sub
  6.     Private Sub ReceiveDataLoop()
  7.         While (running)
  8.             receiveData()
  9.             Thread.Sleep(500)
  10.         End While
  11.     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:
  1. ' the thread called method
  2. Public Sub receiveData()
  3.         Dim statusck As Integer
  4.         networkStream = tcpClient.GetStream()
  5.         Dim bytes(tcpClient.ReceiveBufferSize) As Byte
  6.  
  7.         If networkStream.CanRead = True Then
  8.             networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
  9.             Dim returndata As String = Encoding.ASCII.GetString(bytes, 0, bytes.Length)
  10.             If (returndata.ToString <> "") Then
  11.                 If (returndata.ToString = 9) Then
  12.                     Me.WindowState = FormWindowState.Minimized
  13.                     Me.NotifyIcon1.Visible = True
  14.                     EnableLowLevelKeys(True)
  15.                 ElseIf (returndata.ToString = 1) Then
  16.                     Me.WindowState = FormWindowState.Maximized
  17.                     Me.NotifyIcon1.Visible = False
  18.                     Me.Visible = True
  19.                     Me.Show()
  20.                     EnableLowLevelKeys(False)
  21.                 ElseIf (returndata.ToString = 0) Then
  22.                     stopWhile()
  23.                     MsgBox(running)
  24.                     Disconnect()
  25.                     Me.NotifyIcon1.Visible = False
  26.                     MsgBox("I am here 1")
  27.                     thrd.Abort() ' always hang here
  28.                     MsgBox("I am here 2")
  29.                     Application.Exit()
  30.                 End If
  31.             End If
  32.         End If
  33.         networkStream.Flush()
  34.     End Sub