本文整理汇总了C#中ConcurrentDictionary.AsParallel方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentDictionary.AsParallel方法的具体用法?C# ConcurrentDictionary.AsParallel怎么用?C# ConcurrentDictionary.AsParallel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentDictionary
的用法示例。
在下文中一共展示了ConcurrentDictionary.AsParallel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDocumentMapAsync
private async Task<ConcurrentDictionary<Document, ConcurrentQueue<ValueTuple<ISymbol, IReferenceFinder>>>> CreateDocumentMapAsync(
ConcurrentDictionary<Project, ConcurrentQueue<ValueTuple<ISymbol, IReferenceFinder>>> projectMap)
{
using (Logger.LogBlock(FeatureId.FindReference, FunctionId.FindReference_CreateDocumentMapAsync, this.cancellationToken))
{
Func<Document, ConcurrentQueue<ValueTuple<ISymbol, IReferenceFinder>>> createQueue = d => new ConcurrentQueue<ValueTuple<ISymbol, IReferenceFinder>>();
var documentMap = new ConcurrentDictionary<Document, ConcurrentQueue<ValueTuple<ISymbol, IReferenceFinder>>>();
#if PARALLEL
Roslyn.Utilities.TaskExtensions.RethrowIncorrectAggregateExceptions(cancellationToken, () =>
{
projectMap.AsParallel().WithCancellation(cancellationToken).ForAll(kvp =>
{
var project = kvp.Key;
var projectQueue = kvp.Value;
projectQueue.AsParallel().WithCancellation(cancellationToken).ForAll(symbolAndFinder =>
{
var symbol = symbolAndFinder.Item1;
var finder = symbolAndFinder.Item2;
var documents = finder.DetermineDocumentsToSearch(symbol, project, cancellationToken) ?? SpecializedCollections.EmptyEnumerable<Document>();
foreach (var document in documents.Distinct().WhereNotNull())
{
if (includeDocument(document))
{
documentMap.GetOrAdd(document, createQueue).Enqueue(symbolAndFinder);
}
}
});
});
});
#else
foreach (var kvp in projectMap)
{
var project = kvp.Key;
var projectQueue = kvp.Value;
foreach (var symbolAndFinder in projectQueue)
{
this.cancellationToken.ThrowIfCancellationRequested();
var symbol = symbolAndFinder.Item1;
var finder = symbolAndFinder.Item2;
var documents = await finder.DetermineDocumentsToSearchAsync(symbol, project, this.documents, cancellationToken).ConfigureAwait(false) ?? SpecializedCollections.EmptyEnumerable<Document>();
foreach (var document in documents.Distinct().WhereNotNull())
{
if (this.documents == null || this.documents.Contains(document))
{
documentMap.GetOrAdd(document, createQueue).Enqueue(symbolAndFinder);
}
}
}
}
#endif
Contract.ThrowIfTrue(documentMap.Any(kvp => kvp.Value.Count != kvp.Value.ToSet().Count));
return documentMap;
}
}