Try something like this:
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = True
. . .
Sub Receive(a)
While (True)
If clientsocket.Connected = True Then
. . .
Select Case Microsoft.VisualBasic.Left(ServerSignal, 1)
Case "S" ' show Dialog
Invoke(Sub()
Me.Hide()
test2.Show()
End Sub )
Case "E" ' Resume from Dialog
Invoke(Sub()
Me.Show()
Me.TopMost = True
test2.Hide()
End Sub )
End Select
Else
Thread.Sle ep(300)
End If
End While
End Sub