Bonjour,
Je cherche à rendre mon application plus rapide en utilisant le multi threading.
Voici un exemple :
Deux questions :
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 public static Semaphore _Sema1; // semaphore pour écrire dans la variable contenant les erreurs public static void CheckDossExist(object path) { if (!System.IO.Directory.Exists(Settings.Default.Path + (string)path)) { /* je vais placer ici mes actions longues */ _Sema1.WaitOne(); Variables.ErrorReport += (string)path + "\n"; // variable de type string qui sera affiché dans une MessageBox pour avertir des erreurs _Sema1.Release(); } } public static void Init() { Variables.ErrorReport = ""; _Sema1 = new Semaphore(1, 1); Thread t1 = new Thread(new ParameterizedThreadStart(CheckDossExist)); t1.Start(Constantes.XmlFolder); Thread t2 = new Thread(new ParameterizedThreadStart(CheckDossExist)); t2.Start(Constantes.AsmFolder); Thread t3 = new Thread(new ParameterizedThreadStart(CheckDossExist)); t3.Start(Constantes.PartFolder); while (t1.IsAlive || t2.IsAlive || t3.IsAlive) ;
- Y-a-t-il une autre solution que de nommé les threads (t1, ...) => remplacer le while(t1.IsAlive) par while(ChildThread.IsAlive) pour simplifier mon code.
- Est-ce que j'utilise la bonne méthode pour créer plusieurs entrées dans la même sous fonction avec des paramètres différents ?
Merci par avance.
Et bon weekend.
Partager