I have been trying to make sense of this article http://bensprogrammingwork.blogspot.com/2012/01/progressbar-in-wpf.html
I have the following code on my Button_Click event:
FileInfo existingFile = new FileInfo("C:\\Users\\cle1394\\Desktop\\Apple Foreign Tax Payment Sample Layout Proposed - Sample Data.xlsx");
ConsoleApplication2.Program.ExcelData data = ConsoleApplication2.Program.GetExcelData(existingFile);
The GetExcelData() method takes a few minutes to complete, so I would like to show a progress bar to indicate the estimated time until completion.
However, I don't know how to apply the methods in the tutorial above to my code below for GetExcelData():
public static ExcelData GetExcelData(FileInfo file)
{
ExcelData data = new ExcelData();
data.Countries = new List<Country>();
using (ExcelPackage xlPackage = new ExcelPackage(file))
{
// get the first worksheet in the workbook
ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets[1];
List<string> countryNames = new List<string>
{
"Australia"/*,
"China - Beijing",
"China - Shanghai",
"Hong Kong",
"Hungary",
"Ireland",
"Spain",
"United Kingdom"*/
};
List<string> monthNames = new List<string>
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
foreach (string name in countryNames)
{
Country country = new Country();
Console.WriteLine(name);
country.Name = name;
country.Months = new List<Month>();
foreach (string _name in monthNames)
{
country.Months.Add(GetMonthDataRows(_name, GetMonth(_name, GetCountry(name, worksheet), worksheet), worksheet));
}
country.Totals = GetTotals(country);
data.Countries.Add(country);
// this is where I would like to update the progressbar
}
} // the using statement calls Dispose() which closes the package.
return data;
}
I would like to update the progressbar in the foreach loop above. Can someone show me an example how to do this?