Parallel.ForEach 可枚举键值对?
Parallel.ForEach with Enumerable of KeyValuePairs?
我是否使用了错误的 Parallel ForEach 重载方法?
当我使用普通的 ForEach 循环时,我能够获得当前项目,这是预期的正确类型 (KeyValuePair)。
但是当我使用并行版本时,似乎即使我将鼠标悬停在循环中的当前对象上并且它看起来是正确的类型,我仍然没有获得 Value 和 Key 属性。
提前致谢!
static void TestParallelForEachKeyValuePair(IEnumerable<KeyValuePair<Animal, string>> kvps)
{
foreach (var kvp in kvps)
{
var test = kvp.Key;
}
Parallel.ForEach(kvps, (kvp) =>
{
kvp.
});
}
ForEach
Parallel ForEach
Hovering the current item inside Parallel ForEach
此测试方法有效,但 IntelliSense 未显示 "Key" 和 "Value"
(Windows 表格)。
所以它的 IntelliSense 问题。
static void TestParallelForEachKeyValuePair()
{
List<KeyValuePair<int, string>> test = new List<KeyValuePair<int, string>>();
test.Add(new KeyValuePair<int, string>(1, "test1"));
test.Add(new KeyValuePair<int, string>(2, "test2"));
test.Add(new KeyValuePair<int, string>(3, "test3"));
Parallel.ForEach(test, (x) =>
{
MessageBox.Show(x.Key + " " + x.Value);
});
}
我是否使用了错误的 Parallel ForEach 重载方法? 当我使用普通的 ForEach 循环时,我能够获得当前项目,这是预期的正确类型 (KeyValuePair)。
但是当我使用并行版本时,似乎即使我将鼠标悬停在循环中的当前对象上并且它看起来是正确的类型,我仍然没有获得 Value 和 Key 属性。
提前致谢!
static void TestParallelForEachKeyValuePair(IEnumerable<KeyValuePair<Animal, string>> kvps)
{
foreach (var kvp in kvps)
{
var test = kvp.Key;
}
Parallel.ForEach(kvps, (kvp) =>
{
kvp.
});
}
ForEach
Parallel ForEach
Hovering the current item inside Parallel ForEach
此测试方法有效,但 IntelliSense 未显示 "Key" 和 "Value" (Windows 表格)。 所以它的 IntelliSense 问题。
static void TestParallelForEachKeyValuePair()
{
List<KeyValuePair<int, string>> test = new List<KeyValuePair<int, string>>();
test.Add(new KeyValuePair<int, string>(1, "test1"));
test.Add(new KeyValuePair<int, string>(2, "test2"));
test.Add(new KeyValuePair<int, string>(3, "test3"));
Parallel.ForEach(test, (x) =>
{
MessageBox.Show(x.Key + " " + x.Value);
});
}