Problème backgroundworker et thread
Bonjour à tous
Voilà je chercher à faire un programme qui vérifie si un serveur est en ligne via un port, le problème ne vient pas de là mais plutôt du backgroundworker, en effet comme cette tâche est longue j'ai choisis d'utiliser le backgroundworker, mais j'ai un problème au moment d'afficher une picturebox. j'ai le message :
Citation:
Opération inter-threads non valide : le contrôle 'PictureBox2' a fait l'objet d'un accès à partir d'un thread autre que celui sur lequel il a été créé.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Imports System.Net.Sockets
Public Class Form1
Public Function CheckStatus()
Dim tcpclient As New TcpClient
Try
tcpclient.Connect("adresseIP", 1000)
Return True
Catch Excep As Exception
Return False
End Try
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Hide()
PictureBox2.Hide()
BGW1.RunWorkerAsync()
End Sub
Private Sub BGW1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BGW1.DoWork
If CheckStatus() = True Then
PictureBox1.Show()
Else
PictureBox2.Show()
End If
End Sub
End Class |
Si une personne aurai une solution :)
Merci de vos réponses.
pepsi95