Bonjour,
J'ai codé une routine récursive pour parcourir une arborescence de disque dur, qui fonctionne parfaitement.
J'ai voulu voir si en y intégrant des Threads anonymes, cela pouvait améliorer les performances, sauf que les résultats dans ce mode sont complétement délirants.
Si vous aviez des suggestions pour fiabiliser mon projet, je vous en serais reconnaissant.
Voici le code de la fonction ainsi que son appel :
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 // Appel de la fonction: // Edit1.Text contient de dossier de départ. TThread.CreateAnonymousThread( procedure begin AddThreadedNewNodes(Treeview1.Items, ListBox1.Items, Edit1.Text); end ).Start; // Code de la fonction: procedure AddThreadedNewNodes(ATreeNodes: TTreeNodes; AStrings: TStrings; const AFolder: string; AExtension: string = '.txt'; const ANode: TTreeNode = nil); var LNode: TTreeNode; LInfo: TSearchRec; LNewFolder: string; LSubFolder: string; begin LNewFolder := ExtractFileName(AFolder); LSubFolder := IncludeTrailingPathDelimiter(AFolder); LNode := ATreeNodes.AddChild(ANode, LNewFolder); if FindFirst(LSubFolder + '*', faAnyFile, LInfo) = 0 then Begin repeat if (LInfo.Name <> '.') and (LInfo.Name <> '..') then begin If (LInfo.Attr And faDirectory) = faDirectory then begin TThread.CreateAnonymousThread( procedure begin AddThreadedNewNodes(ATreeNodes, AStrings, LSubFolder + LInfo.Name, AExtension, LNode); end ).Start; end else begin if ExtractFileExt(LInfo.Name) = AExtension then begin TThread.Synchronize(nil, procedure begin ATreeNodes.AddChild(LNode, LInfo.Name); AStrings.Add(LSubFolder + LInfo.Name); end ); end; end; end; until FindNext(LInfo) <> 0; FindClose(LInfo); end; end;
Partager