gpt4 book ai didi

c# - 进度条不更新

转载 作者:行者123 更新时间:2023-11-30 19:14:23 24 4
gpt4 key购买 nike

我有以下代码将数据写入 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("<?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;
}
}
}

它使用从数据库获取数据的同一个 BackgroundWorker。我的进度条在从数据库读取时正确显示进度。然而,在将 XML 写入的进度条归零后,即使该过程正确完成,它也只是停留在 0。

谁能告诉我为什么?

最佳答案

会不会是 (count/customers) 被截断为零(两个整数之间的除法)?

关于c# - 进度条不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/709488/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com