【发布时间】:2013-01-30 04:33:51
【问题描述】:
我正在尝试从 SharePoint 2010 检索同义词,但我的代码存在以下问题:它循环通过没有索引器的 keywordCollection。执行foreach 花费的时间太长,因为实例化一个新关键字大约持续 5-10 毫秒,到目前为止大约有 8000 个关键字,大约需要 80 秒才能完成。
到目前为止我尝试过的事情:
获取枚举器 -> 也需要 80 秒
将集合转换为列表 -> 未知原因失败。
代码示例:
KeywordContext keywordContext = fastProxy.KeywordContext;
SearchSettingGroupCollection searchSettingGroupCollection = keywordContext.SearchSettingGroups;
foreach (SearchSettingGroup searchSettingGroup in searchSettingGroupCollection)
{
if (searchSettingGroup.Name == siteId.ToString())
{
foreach (Keyword keyword in searchSettingGroup.Keywords)
{
//the rest of the work here, per total takes about 470ms
}
}
}
有没有办法在不使用foreach 语句的情况下循环遍历集合,该语句每次都会实例化一个新的object<T>?
谢谢!
【问题讨论】:
-
"
// the rest of the work here" -
//剩下的工作 -> 只是一些字符串操作,在这 80 秒中总共需要 470 毫秒。问题是每当 foreach 实例化一个新的只读关键字时,它需要大约 10 毫秒,这是我的问题。
-
所以你不能跳过大部分关键字,对吧?也就是说,您的代码似乎需要访问集合中的每个关键字,对吗?
-
没错,我需要一种方法来访问该集合中的每个关键字,而无需像“foreach”那样实例化一个新关键字
标签: performance sharepoint collections foreach