问题描述
是否可以计算和报告使用树结构的深度优先遍历执行的任务的进度?特别是,它是一个遍历树结构并使用C#和EPPlus创建电子表格并将该树中的数据写入该电子表格的程序。
这是在BackgroundWorker
中执行的。 (我知道将推荐使用Task
,但是BackgroundWorkers在整个项目中都使用,并且不能更改)。 BackgroundWorker.ReportProgress()
用于更新WinForms应用程序中的进度条。
这是执行此任务的代码(至少是代码的重要部分)。正如代码中所注释的那样,在写入电子表格的总数中,树中的“节点”数构成了进度的基础。
public void render(ref System.ComponentModel.BackgroundWorker worker)
{
// create a new worksheet
OfficeOpenXml.ExcelWorksheet worksheet = excel.Workbook.Worksheets.Add("revisions");
// write the Metadata
// ...
// write the headers
// ...
// perform a depth first traversal of the structure
Queue<Node> traversalState = new Queue<Node>();
rowNumber = HEADER;
foreach (Node node in revisions)
{
traversalState.Enqueue(node);
}
while (traversalState.Count > 0)
{
// get the node from the queue
Node currNode = traversalState.Dequeue();
// do stuff with it
// want to report progress for this,that is how many "nodes" are written to the spreadsheet
worksheet.Cells[row,1].Value = node.getPath();
worksheet.Cells[row,2].Value = node.getDescription();
// put the node's children onto the queue
foreach (Node newNode in node)
{
traversalState.Enqueue(newNode);
}
rowNumber++;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)