c# - 根据字典集合大小增加进度指示器

标签 c# func

我正在尝试找出一种方法来报告使用以下代码循环遍历字典的进度:

int progressTracker = 0;
foreach (KeyValuePair<string, Func<T>> methodPair in DicitionaryCollection)
{
progressTracker++;
progressTracker = (100 * progressTracker) / DicitionaryCollection.Count;
// do something with progress and collection contents
}

然而,这会不断返回值,在值方面有点跳跃。有什么想法吗?

最佳答案

使用不同的变量。

int currentProgress= 0;
foreach (KeyValuePair<string, Func<T>> methodPair in DicitionaryCollection)
{
  currentProgress++;
  int progressTracker = (100 * currentProgress) / DicitionaryCollection.Count;
  // do something with progress and collection contents
}

关于c# - 根据字典集合大小增加进度指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20166417/

相关文章:

c# - 如何以 Func 类型的表达式作为参数调用方法

c# - Action/Func vs Methods,有什么意义?

c# - Visual C# - 将文本框的内容写入 .txt 文件

c# - 如何管理用户可修改的查找表

C#如何解决循环对象引用

c# - 使用反射和运行时已知的类型调用 Func 对象

c# - System.Action<T> 作为 EventHandler

c# - 这个语法是什么意思? Func<Task, TResult> 样本函数

c# - 多线程时是否必须锁定数据库连接?

c# - 如何在 C# 中使用 WM_Close?