public IEnumerable <ExternalApplication> GetAllRunningApplications() { foreach (var window in SystemWindow.GetAllWindows()) { // Ignore invisible and system windows if (!window.IsVisible() || window.IsSystemWindow()) { continue; } using var process = window.TryGetProcess(); var executableFilePath = process?.TryGetExecutableFilePath(); // Ignore explorer if (string.Equals(Path.GetFileNameWithoutExtension(executableFilePath), "explorer", StringComparison.OrdinalIgnoreCase)) { continue; } if (!string.IsNullOrWhiteSpace(executableFilePath)) { yield return(new ExternalApplication(executableFilePath)); } } }
public IReadOnlyList <ExternalApplication> GetAllRunningApplications() { var result = new List <ExternalApplication>(); // Enumerate all top-level windows foreach (var window in SystemWindow.GetAllWindows()) { using var _ = window; // Ignore invisible and system windows if (!window.IsVisible() || window.IsSystemWindow()) { continue; } using var process = window.GetProcess(); var executableFilePath = process?.GetExecutableFilePath(); // Ignore explorer if (string.Equals(Path.GetFileNameWithoutExtension(executableFilePath), "explorer", StringComparison.OrdinalIgnoreCase)) { continue; } if (!string.IsNullOrWhiteSpace(executableFilePath)) { result.Add(new ExternalApplication(executableFilePath)); } } return(result); }
public IEnumerable <ExternalApplication> GetAllRunningApplications() { foreach (var window in SystemWindow.GetAllWindows()) { if (!window.IsVisible() || window.IsSystemWindow()) { continue; } using var process = window.TryGetProcess(); var executableFilePath = process?.TryGetExecutableFilePath(); var executableFileName = Path.GetFileNameWithoutExtension(executableFilePath); if (string.IsNullOrWhiteSpace(executableFilePath) || string.IsNullOrWhiteSpace(executableFileName)) { continue; } if (_ignoredApplicationNames.Contains(executableFileName)) { continue; } yield return(new ExternalApplication(executableFilePath)); } }