private void UpdateAppsAndUrls() { if (isUpdateAppsUrls) { return; } try { isUpdateAppsUrls = true; var allApps = AppInfoFactory.GetVisibleAppsInfo(); var appInfoComparer = new AppInfoComparer(); var apps = allApps .Where(a => string.IsNullOrEmpty(a.Domain)) .Except(OpenedApps, appInfoComparer) .ToArray(); var urls = AddMainDomain(allApps.Where(a => !string.IsNullOrEmpty(a.Domain))) .Distinct(appInfoComparer) .Except(OpenedForegroundUrls, appInfoComparer) .ToArray(); Application.Current.Dispatcher.Invoke(() => { OpenedApps.Add(apps); OpenedForegroundUrls.Add(urls); }); } finally { isUpdateAppsUrls = false; } }
async void RefreshAppList() { try { Refreshing = true; await Task.Run(() => { var apps = AppInfoFactory.GetVisibleAppsInfo(); var expandedApps = apps.Select(a => new ExpandedAppInfo(a)).ToList(); var urls = new List <ExpandedAppInfo>(); foreach (var app in expandedApps) { if (!string.IsNullOrWhiteSpace(app.AppInfo.Domain)) { urls.Add(new ExpandedAppInfo(app.AppInfo.Copy())); app.AppInfo.Domain = string.Empty; } } var uniqueApps = expandedApps.GroupBy(x => x.AppInfo.Description).Select(a => a.First()).ToList(); uniqueApps.AddRange(urls); App.Current.Dispatcher.Invoke(() => { Apps.Clear(); foreach (var app in uniqueApps) { Apps.Add(app); } }); }); } finally { Refreshing = false; } }