Bonjour.

Pourriez vous m'expliquer pourquoi en debug, si je met un breakpoint dans un thread, lorsque celui ci est atteind, ca met tous les threads en cours, et non uniquement le thread concerné?

Il y a t'il un moyen d'éviter cela?

Ci dessous un ptit code d'exemple, mettez un breakpoint dans la methode ThreadA ou ThreadB, lancez les 2 threads:

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
 
namespace TestThreadBreakPoint
{
    class Program
    {
        static bool continueA = false;
        static bool continueB = false;
        static Thread thA;
        static Thread thB;
 
       static void ThreadA()
        {
            int index = 0;
            do
            {
                Console.WriteLine("ThreadA : {0}", index);
                Thread.Sleep(1000);
                index++;
            } while (continueA);
        }
 
        static void ThreadB()
        {
            int index = 0;
            do
            {
                Console.WriteLine("ThreadB : {0}", index);
                Thread.Sleep(1000);
                index++;
            } while (continueB);
        }
 
 
 
        static void Main(string[] args)
        {
            bool continueG = true;
            do
            {
                Console.WriteLine("1-Start/Stop ThreadA\r\n2-Start/Stop ThreadB\r\n3-Quit");
                String line = Console.ReadLine();
                switch (line)
                {
                    case "1":
                        if (continueA)
                            Stop(1);
                        else
                            Start(1);
                        break;
                    case "2":
                        if (continueB)
                            Stop(2);
                        else
                            Start(2);
                        break;
                    case "0":
                        continueA = false;
                        continueB = false;
                        continueG = false;
                        break;
                }
            } while (continueG);
        }
 
        static void Start(int ind)
        {
            if (ind == 1)
            {
                continueA = true;
                thA = new Thread(ThreadA);
                thA.Start();
                Console.WriteLine("threadA lancé");
            }
            else
            {
                continueB = true;
                thB = new Thread(ThreadB);
                thB.Start();
                Console.WriteLine("threadB lancé");
            }
        }
 
        static void Stop(int ind)
        {
            if (ind == 1)
            {
                continueA = false;
                thA.Join(10000);
                Console.WriteLine("threadA terminé");
 
            }
            else
            {
                continueB = false;
                thB.Join(10000);
                Console.WriteLine("threadB terminé");
            }
        }
 
     }
}