private void Progress_ProgressChanged(object sender, ProgressReportService e) { if (e.PercComplete == 100) { this.Close(); mainWindow.Show(); } }
/// <summary> /// Sets the list of countries to be displayed in the UI /// </summary> /// <returns>List of countries</returns> public static async Task <List <Country> > GetCountriesListAsync(IProgress <ProgressReportService> progress) { DataFlow data = new DataFlow(); List <Country> Countries = new List <Country>(); Countries = await data.ReturnCountriesData(); string PathImage = Path.Combine($@"{Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures)}\Images\FlagImages"); DirectoryInfo dir = new DirectoryInfo(PathImage); var files = dir.GetFiles(); ProgressReportService report = new ProgressReportService(); report.PercComplete = 0; if (Countries != null) { List <Country> temp = new List <Country>(); try { await Task.Run(() => { Parallel.ForEach <Country>(Countries, (country) => { foreach (var file in files) { if (file.Name.Contains(country.Name)) { if (country.Gini == null) { country.Gini = "Information not available"; } if (country.Capital == "") { country.Capital = "Information not available"; } if (country.Region == "") { country.Region = "Information not available"; } if (country.Subregion == "") { country.Subregion = "Information not available"; } country.Image = new BitmapImage(new Uri(file.FullName)); country.Image.Freeze(); } } }); }); } catch { } } var route = Countries.Where(c => c.Image == null); foreach (var item in route) { Countries.Remove(item); item.Image = new BitmapImage(new Uri(@"\Images\no-image-available.jpg", UriKind.Relative)); Countries.Add(item); break; } report.PercComplete = 100; progress.Report(report); return(Countries); }