Bonjour,
Dans la classe suivante:
Je cherche à réaliser une boucle sur des threads afin de lancer la méthode "CalculateValueClient" 1000 fois au total mais pas plus de 10 fois en même temps et de faire en sorte que, par exemple, dès que le thread qui s'occupe de i ait fini, alors, celui qui s'occupe de i+ se lance!
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 static void Main(string[] args) { ModelAccessor monModel = new ModelAccessor(); Thread th = new Thread(new ParameterizedThreadStart(monModel.CalculateValueClient)); Thread th1 = new Thread(new ParameterizedThreadStart(monModel.CalculateValueClient)); Thread th2= new Thread(new ParameterizedThreadStart(monModel.CalculateValueClient)); Thread th3 = new Thread(new ParameterizedThreadStart(monModel.CalculateValueClient)); Thread th4 = new Thread(new ParameterizedThreadStart(monModel.CalculateValueClient)); Thread th5 = new Thread(new ParameterizedThreadStart(monModel.CalculateValueClient)); Thread th6 = new Thread(new ParameterizedThreadStart(monModel.CalculateValueClient)); Thread th7 = new Thread(new ParameterizedThreadStart(monModel.CalculateValueClient)); Thread th8 = new Thread(new ParameterizedThreadStart(monModel.CalculateValueClient)); Thread th9 = new Thread(new ParameterizedThreadStart(monModel.CalculateValueClient)); for (int i = 0; i < 1000; i+=10) { th.Start(i); th1.Start(i+1); th2.Start(i+2); th3.Start(i+3); th4.Start(i+4); th5.Start(i+5); th6.Start(i+6); th7.Start(i+7); th8.Start(i+8); th9.Start(i+9);
Le bout de code ci-dessus ne réalise pas cette dernière condition...
Quelqu'un peut me filer un coup de main?
Merci d'avance!
Partager