private void ApplicationLaunched(object sender, EventArrivedEventArgs e) { ActionWrappers.TryCatchDiscard(() => { var processId = Convert.ToInt32(e.NewEvent.Properties[WmiProcessidName].Value); var process = Process.GetProcessById(processId); RaiseOnNewProcess(process); }); }
private void BuildInitialProcesses(CancellationToken token = default) { var allProcesses = Process.GetProcesses(); _processes = new HashSet <Process>(allProcesses.Length); foreach (var process in allProcesses) { if (token.IsCancellationRequested) { return; } ActionWrappers.TryCatchDiscard(() => { var processPath = Path.GetFullPath(process.GetExecutablePath()); if (string.Equals(processPath, _applicationPath, StringComparison.OrdinalIgnoreCase)) { _processes.Add(process); } }); } }