Currently I am working on a project to get information from the TFS trying to build a custom tool
I have decided to improve the performance of the tool and i got stuck with 1 issue using the Parallel option (.Net 4+)
Remark: I have tried placing safe thread on the queryresults and item it didn't help code samples are at the bottom
I am trying to perform the next code:
WorkItemCollection queryResults;
//Query run to populate the collection
Parallel.ForEach<WorkItem>(queryResults.Cast<WorkItem>(), item => {
Console.WriteLine(item.Fields.GetById(AttributeCode.Default.RemainingWork).Value);
});
Error quote:
An exception of type 'Microsoft.TeamFoundation.TeamFoundationServiceUnavailableException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll but was not handled in user code
Log from Exception Catch:
A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Dictionary
2.KeyCollection.Enumerator.MoveNext() at Microsoft.TeamFoundation.WorkItemTracking.Client.PagingFieldReader.ProcessFields(Int32 row, IEnumerable
1 fieldIds, Dictionary2 fields) at Microsoft.TeamFoundation.WorkItemTracking.Client.PagingFieldReader.ProcessRevision(Int32 row, Dictionary
2 rowMap, Dictionary2 plainFields, Dictionary
2 textFields) at Microsoft.TeamFoundation.WorkItemTracking.Client.PagingFieldReader.Read(Int32 row, Int32[] fields) at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemCollection.QueryFieldValues(Int32 index, Int32[] fields) at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.get_IsAccessDenied() at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.QueryFieldValue(Int32 field) at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemFieldData.GetFieldValue(Int32 id, Int32 revision) at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.CheckUpdateCachedData() at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.get_Type() at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.get_Fields()
Block protection on the items not sure if i've done it right:
WorkItemCollection queryResults;
//Query run to populate the collection
BlockingCollection<WorkItem> bc = new BlockingCollection<WorkItem>();
WorkItem temp;
Parallel.ForEach<WorkItem>(queryResults.Cast<WorkItem>(), item =>
{
bc.Add(item);
if (bc.TryTake(out temp))
Console.WriteLine(temp.Fields[CoreField.CreatedBy]);
});
Error:
A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Dictionary
2.KeyCollection.Enumerator.MoveNext() at Microsoft.TeamFoundation.WorkItemTracking.Client.PagingFieldReader.ProcessFields(Int32 row, IEnumerable
1 fieldIds, Dictionary2 fields) at Microsoft.TeamFoundation.WorkItemTracking.Client.PagingFieldReader.ProcessRevision(Int32 row, Dictionary
2 rowMap, Dictionary2 plainFields, Dictionary
2 textFields) at Microsoft.TeamFoundation.WorkItemTracking.Client.PagingFieldReader.Read(Int32 row, Int32[] fields) at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemCollection.QueryFieldValues(Int32 index, Int32[] fields) at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.get_IsAccessDenied() at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.QueryFieldValue(Int32 field) at Microsoft.TeamFoundation.A first chance exception of type 'System.InvalidOperationException' occurred in SW-QA Tasks.exe WorkItemTracking.Client.WorkItemFieldData.GetFieldValue(Int32 id, Int32 revision) at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.CheckUpdateCachedData() at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.get_Type() at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.get_Fields() System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Dictionary2.KeyCollection.Enumerator.MoveNext() at Microsoft.TeamFoundation.WorkItemTracking.Client.PagingFieldReader.ProcessFields(Int32 row, IEnumerable
1 fieldIds, Dictionary`2 fields) at Microsoft.TeamFoundation.WorkItemTracking.Client.PagingFieldReader.ProcessRevision(Int32 row, D