Bonjour,

J'essaye d'arrêter un thread après un clic sur un bouton mais le thread en question ne s'arrête pas !

Je vous mets le code :

Code c# : 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
35
36
37
38
39
40
41
42
43
 
public DrivingMode()
        {
            InitializeComponent();
            monThread2 = new Thread(new ThreadStart(CallPositionsThreading));
            monThread2.Start(); // On lance le thread permettant l'affichage temps réel des positions.       
        }
 
        private void CallPositionsThreading()
        {
            if (nbr_position < 15)
            {
                UpdateCarPosition(nbr_position);
                Thread.Sleep(0);
            }
        }
 
        private delegate void CallPositionsThreadingDelegate(int nbr_position);
        private void UpdateCarPosition(int nbr_position)
        {
            if (this.InvokeRequired)
            {
                // we were called on a worker thread
                // marshal the call to the user interface thread
                this.Invoke(new CallPositionsThreadingDelegate(UpdateCarPosition), new object[] { nbr_position });
                return;
            }
 
            // this code can only be reached
            // by the user interface thread
 
            Coord.GetJustOnePosition(positions,DriverCoord,nbr_position);
            DisplayMapFromOneCoord(positions, drivingmodemap.Height, drivingmodemap.Width,500);
 
        }
 
 
        private void menuItem1_Click(object sender, EventArgs e)
        {
           // Malgré l'Abort, le thread n'est pas stoppé !
            monThread2.Abort();
            Close();
        }

Une idée?
Merci!