Progress Bar not updating
- by Bailz
I have the following piece of code to write data to an XML file.
private void WriteResidentData()
{
int count = 1;
status = "Writing XML files";
foreach (Site site in sites)
{
try
{
//Create the XML file
StreamWriter writer = new StreamWriter(path + "\\sites\\" + site.title + ".xml");
writer.WriteLine("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>");
writer.WriteLine("<customer_list>");
foreach (Resident res in site.GetCustomers())
{
bw.ReportProgress((count / customers) * 100);
writer.WriteLine("\t<customer>");
writer.WriteLine("\t\t<customer_reference>" + res.reference + "</customer_reference>");
writer.WriteLine("\t\t<customer_name>" + res.name + "</customer_name>");
writer.WriteLine("\t\t<customer_address>" + res.address + "</customer_address>");
writer.WriteLine("\t\t<payment_method>" + res.method + "</payment_method>");
writer.WriteLine("\t\t<payment_cycle>" + res.cycle + "</payment_cycle>");
writer.WriteLine("\t\t<registered>" + CheckWebStatus(res.reference) + "</registered>");
writer.WriteLine("\t</customer>");
count++;
}
writer.WriteLine("</customer_list>");
writer.Close();
}
catch (Exception ex)
{
lastException = ex;
}
}
}
It's using the same BackgroundWorker that gets the data from the database. My progress bar properly displays the progress whilst it is reading from the database. However, after zeroing the progress bar for the XML writing it simply sits at 0 even though the process is completing correctly.
Can anyone suggest why?