Hola a todos, espero me puedan ayudar, tengo una aplicación donde se conectan los Clientes al servidor, y desde el servidor les envío mensajes (funciona), pero en determinado momento el servidor manda el mensaje "IniciarTest", el cliente verifica el mensaje y abre un formulario nuevo donde empieza a contestar pregunta por pregunta.
Pero cuando intenta abrir el nuevo formulario me manda el siguiente error:
Cita: cannot be instantiated because the current thread is not in a single-threaded apartment
Para el cliente conectarse al servidor hago el thread:
Código:
Dim thr As New Thread(AddressOf ConectarseCliente)
thr.Start()
Código:
Private Sub ConectarseCliente()
With Cliente
If .EstadoCon = False Then
.IPDelHost = lbEquipo.Text
.PuertoDelHost = 8050
.Conectar()
End If
End With
Y cuando el cliente recibe un mensaje, se genera este evento:
Código:
Private Sub SocketCliente_DatosRecibidos(ByVal datos As String) Handles Cliente.DatosRecibidos
lbTemporal.Text = datos
Try
Select Case lbTemporal.Text
Case "IniciarTest"
frmExamen.Show()
Case "Siguiente"
frmExamen.siguiente_pregunta()
End Select
Catch ex As Exception
MsgBox("Error berraco!!" & ex.Message)
End Try
txtConversa.Text = datos & vbCrLf & vbCrLf & txtConversa.Text
End Sub
Puse el CheckForIllegalCrossThreadCalls = False, pero tampoco funcionó con eso.
También le puse thr.SetApartmentState(ApartmentState.STA) y se queda bloqueado.
¿Qué hago? por favor ayúdenme