-
-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathExamples.QueryParallelSpeed.cs
More file actions
67 lines (58 loc) · 2.86 KB
/
Copy pathExamples.QueryParallelSpeed.cs
File metadata and controls
67 lines (58 loc) · 2.86 KB
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
60
61
62
63
64
65
66
67
using System.Diagnostics;
namespace EventViewerX.Examples {
internal partial class Examples {
public static void QueryParallelSpeed() {
var machineNames = new List<string?> { "AD1", "AD2", "AD3" }; // Add your machine names here
var eventIds = new List<int> { 4932, 4933 }; // Add your event IDs here
Parallel.ForEach(machineNames, machine => {
foreach (var eventObject in EventLogEngine.ReadChannel(
"Security",
new EventFilter { EventIds = eventIds },
machine)) {
}
});
}
public static async Task QueryParallelCompare() {
var machineNames = new List<string?> { "AD1", "AD2", "AD3" }; // Add your machine names here
var eventIds = new List<int> { 4932, 4933 }; // Add your event IDs here
var stopwatch = Stopwatch.StartNew();
int eventCount1 = 0;
Parallel.ForEach(machineNames, machine => {
foreach (var eventObject in EventLogEngine.ReadChannel(
"Security",
new EventFilter { EventIds = eventIds },
machine)) {
Interlocked.Increment(ref eventCount1);
}
});
stopwatch.Stop();
Console.WriteLine($"Parallel.ForEach method took {stopwatch.ElapsedMilliseconds} ms and returned {eventCount1} events.");
stopwatch.Restart();
int eventCount2 = 0;
await foreach (var eventObject in EventLogEngine.ReadChannelsAsync(
["Security"],
machineNames,
new EventFilter { EventIds = eventIds })) {
eventCount2++;
}
stopwatch.Stop();
Console.WriteLine($"QueryLogsParallel method took {stopwatch.ElapsedMilliseconds} ms and returned {eventCount2} events.");
stopwatch.Restart();
int eventCount3 = 0;
foreach (var eventObject in EventLogEngine.ReadChannels(
["Security"],
machineNames,
new EventFilter { EventIds = eventIds },
new EventLogQueryOptions { MaxConcurrency = 1 })) {
eventCount3++;
}
stopwatch.Stop();
Console.WriteLine($"QueryLogsSequential method took {stopwatch.ElapsedMilliseconds} ms and returned {eventCount3} events.");
if (eventCount1 == eventCount2 && eventCount2 == eventCount3) {
Console.WriteLine("All methods returned the same number of events.");
} else {
Console.WriteLine("The methods returned a different number of events.");
}
}
}
}