当我连接时,背景颜色变为“SpringGreen”,当发生Wxeption时,它们变为“黄色”,出现消息框(“Timer on”),背景颜色变为“Gray”? ?
但当Exece发生在ReceiveMessag()时,颜色变为“黄色”,调试行显示启用了trmReboot,但没有消息框,背景颜色也没有变为“灰色”????
为什么定时器不能以ReceiveMessag()Exeption ??
开头 Private Sub Connect()
Try
_client = New TcpClient(strIP, intPort)
Threading.ThreadPool.QueueUserWorkItem(AddressOf ReceiveMessages)
Try
If _client.Connected Then
login()
tsStatusIP.BackColor = Color.SpringGreen
tsStatusIPport.BackColor = Color.SpringGreen
tsStatusIP.Text = "IP adres: " + strIP
tsStatusIPport.Text = "Server poort nummer: " + intPort.ToString
booConnected = True
End If
Catch ex As Exception
'MsgBox(ex.Message)
End Try
Catch ex As Exception
ExecptionHandler()
End Try
End Sub
Private Sub ReceiveMessages(state As Object)
Try
While True
Dim ns As NetworkStream = _client.GetStream()
Dim toReceive(100000) As Byte
ns.Read(toReceive, 0, toReceive.Length)
Dim txt As String = Encoding.ASCII.GetString(toReceive)
messagerecieved(txt)
' If Application.OpenForms().OfType(Of frmReceivedData).Any = True Then 'check if form is open
If txtReceivedData.Visible = True Then
txtReceivedData.Text = txtReceivedData.Text + txt
End If
' End If
End While
Catch ex As Exception
ExecptionHandler()
End Try
End Sub
Private Sub ExecptionHandler()
tsStatusIP.BackColor = Color.Yellow
tsStatusIPport.BackColor = Color.Yellow
booConnected = False
tmrReboot.Enabled = True
Debug.Print(tmrReboot.Enabled)
End Sub
Private Sub tmrReboot_Tick(sender As Object, e As EventArgs) Handles tmrReboot.Tick
MsgBox("timer on")
tsStatusIP.BackColor = Color.Gray
tsStatusIPport.BackColor = Color.Gray
End Sub