Bonjour à tous,
est ce que quelqu'un peut m'expliquer pourquoi je ne sors jamais du while dans ce code ?
En fait le break est exécuté seulement si j'utilise la variable p_ok ... je pense qu'il s'agit d'un truc lié au compilateur , non ?
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 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace FileWatcher { class MyFileWatcher { public Boolean p_ok = false; FileSystemWatcher fsw = new FileSystemWatcher(); public MyFileWatcher(){ fsw.Path = @"C:\temp"; fsw.Filter = "*.txt"; fsw.IncludeSubdirectories = false; fsw.Changed += new FileSystemEventHandler(this.fsw_Changed); fsw.NotifyFilter = System.IO.NotifyFilters.LastWrite; } public void Run(){ Console.Out.WriteLine("Go"); fsw.EnableRaisingEvents = true; while (true) { if (this.p_ok) { Console.Out.WriteLine("break"); break; } } } private void fsw_Changed(object sender, FileSystemEventArgs e){ this.p_ok = true; Console.Out.WriteLine(e.Name + " - " + e.ChangeType + " - "); } } }
Partager