djdagobert
New member
- Joined
- Jul 28, 2005
- Messages
- 2
- Programming Experience
- 5-10
Hi,
I've the following problem:
I've a main thread, that creates another thread that has an open connection and is waiting for a response. (In particular: is waiting for a string with a newline at the end)
While this thread is waiting for that line, I want to kill that thread from the main-thread, but the waiting thread will not terminate. WHY?
Here is my code:
I've the following problem:
I've a main thread, that creates another thread that has an open connection and is waiting for a response. (In particular: is waiting for a string with a newline at the end)
While this thread is waiting for that line, I want to kill that thread from the main-thread, but the waiting thread will not terminate. WHY?
Here is my code:
VB.NET:
Dim myThread As New Thread(AddressOf connect())
myThread.Start()
Private Sub MIT_Config_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MIT_Config.Click
myThread.Abort()
myThread.Join()
End Sub
Private Sub connect()
Dim client As Net.Sockets.TcpClient
Try
client.Connect(server, port)
Dim myStreamReader As New IO.StreamReader(client.GetStream())
Dim myStreamWriter As New IO.StreamWriter(client.GetStream())
Dim line As String
While True
line = myStreamReader.ReadLine()
End While
Catch e As ThreadAbortException
MsgBox("Thread wurde abgebrochen:" & Chr(13) & Chr(10) & e.ToString(), MsgBoxStyle.Information, "Information")
Catch e As Exception
MsgBox("Error in Connecting to Server:" & Chr(13) & Chr(10) & e.ToString(), MsgBoxStyle.Information, "Error")
Finally
client.Close()
End Try
End Sub