Code:
Parallel.ForEach(
infoMap,
map =>
{
var workItem = map.WorkItem;
var parentInViews = viewMaps;
var workbenchItem = map.WorkbenchItem;
string LinkType = string.Empty;
WorkItemLinkCollection linkedWorkItems = workItem.WorkItemLinkHistory;
if (linkedWorkItems != null && linkedWorkItems.Count > 0)
LinkType = linkedWorkItems[0].LinkTypeEnd.LinkType.ReferenceName;
else if (workItem != null)
LinkType = workItem.Store.WorkItemLinkTypes.LinkTypeEnds["Parent"].LinkType.ReferenceName;
if (!string.IsNullOrEmpty(LinkType))
{
var viewMap = parentInViews.FirstOrDefault();
if (viewMap != null)
{
var linkName = LinkType;
var childType = viewMap.ChildType;
ILinkItem itm = Factory.BuildLinkItem(linkName, workbenchItem, workbenchItem);
lock (Addparents)
{
Addparents.Add(itm);
}
}
}
});
Factory.BuildLinkItem definition:
public static ILinkItem BuildLinkItem(string linkName, IWorkbenchItem parent, IWorkbenchItem child)
{
return new LinkItem { LinkName = linkName ?? string.Empty, Child = child, Parent = parent };
}
Totally 658 items are present and it takes nearly 10 seconds to execute the above Parallel.ForEach function.
Is it possible to reduce the execution time and if so, please suggest me a solution. Thanks.
Note: Apart from Parallel.ForEach, if any alternate method is there to increase the performance and reduce the execution time also, Please suggest. Thanks.
Addparents.Add(itm)? Why not do a parallel select with a.ToList()to put the items in a list?Addparents.Add(itm);toparallel select with a .ToList(). Thanks.