Bonsoir !

J'aimerais faire un programme qui "ping" une plage d'adresse IP.

Dans une version de mon programme cela marchait très bien mais le traitement prenait énormément de temps !

On m'a donc conseillé d'utiliser les threads. Notion que je connais pas du tout.

Grâce à internet j'ai donc trouvé un peu de documentation pour pouvoir utiliser les threads, le seul soucis est que je rencontre des erreurs que je ne comprends pas et je ne sais pas si je les utilises bien. :s

L'erreur rencontrée est :
Opération inter-threads non valide : le contrôle 'LIB_SCAN2' a fait l'objet d'un accès à partir d'un thread autre que celui sur lequel il a été créé.
mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
29
30
31
32
33
34
        public void BT_SCAN_Click(object sender, EventArgs e)
        {
            Thread th = new Thread(new ParameterizedThreadStart(pingue));
            Thread th2 = new Thread(new ParameterizedThreadStart(pingue));
            Thread th3 = new Thread(new ParameterizedThreadStart(pingue));
            int j = 100, k = 200; ;
 
            for (int i = 1; i < 100; i++)
            {
                th.Start(i);
                th2.Start(j);
                th3.Start(k);            
 
                th.Join();
                th2.Join();
                th3.Join();
 
                j++;
                k++;
            }
        }
 
        public void pingue(object tst)
        {
            Ping pingSender = new Ping();
            PingOptions options = new PingOptions();
            String data = new String('a', 8);
            byte[] buffer = Encoding.ASCII.GetBytes(data);
            int timeout = 120;
 
            IPHostEntry entry = Dns.GetHostEntry("192.168.1."+(tst.ToString()));
            PingReply reply = pingSender.Send(entry.AddressList[0], timeout, buffer, options);
            LIB_SCAN2.Items.Add("192.168.1."+(tst.toString())).SubItems.Add(reply.RoundtripTime.ToString() + " ms");
        }
Merci d'avance .