我有以下代码将数据写入XML文件.
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(""); writer.WriteLine(""); foreach (Resident res in site.GetCustomers()) { bw.ReportProgress((count / customers) * 100); writer.WriteLine("\t "); writer.Close(); } catch (Exception ex) { lastException = ex; } } }"); writer.WriteLine("\t\t "); count++; } writer.WriteLine("" + res.reference + " "); writer.WriteLine("\t\t" + res.name + " "); writer.WriteLine("\t\t" + res.address + " "); writer.WriteLine("\t\t" + res.method + " "); writer.WriteLine("\t\t" + res.cycle + " "); writer.WriteLine("\t\t" + CheckWebStatus(res.reference) + " "); writer.WriteLine("\t
它使用相同的BackgroundWorker从数据库中获取数据.我的进度条在从数据库中读取时正确显示进度.但是,在将XML写入的进度条归零后,即使进程正确完成,它也只是位于0.
谁有人建议为什么?
可能是(计数/客户)被截断为零(两个整数之间的划分)?
我认为应该是(数*100)/客户,假设你想要一个百分比完成.