-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTasks.cs
27 lines (24 loc) · 853 Bytes
/
Tasks.cs
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
namespace DataFlowVsTasks;
public static class Tasks {
public static void OnlyTasks(bool writeToDisk) {
var files = Directory.EnumerateFiles(Data.FilesDir, "*").ToArray();
var tasks = new Task[files.Length];
for (var i = 0; i < files.Length; i++) {
var file = files[i];
var task = Task.Run(() => ProcessFile(file, writeToDisk));
tasks[i] = task;
}
Task.WaitAll(tasks);
}
private static void ProcessFile(string file, bool writeToDisk) {
var read = Actions.ReadFile(file);
var search = Actions.SearchFile(read);
var enrich = Actions.EnrichFileCount(search);
if (writeToDisk) {
Actions.WriteFile(enrich);
}
else {
Actions.DontWriteToDisk(enrich);
}
}
}