Пример #1
0
        private async Task ProcessDocumentQueueAsync(
            Document document,
            HashSet <ISymbol> documentQueue,
            CancellationToken cancellationToken)
        {
            await _progress.OnFindInDocumentStartedAsync(document, cancellationToken).ConfigureAwait(false);

            SemanticModel?model = null;

            try
            {
                model = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);

                // start cache for this semantic model
                FindReferenceCache.Start(model);

                foreach (var symbol in documentQueue)
                {
                    await ProcessDocumentAsync(document, model, symbol, cancellationToken).ConfigureAwait(false);
                }
            }
            finally
            {
                FindReferenceCache.Stop(model);

                await _progress.OnFindInDocumentCompletedAsync(document, cancellationToken).ConfigureAwait(false);
            }
        }
        private async Task ProcessDocumentQueueAsync(
            Document document,
            List <ValueTuple <SymbolAndProjectId, IReferenceFinder> > documentQueue,
            ProgressWrapper wrapper)
        {
            await _progress.OnFindInDocumentStartedAsync(document).ConfigureAwait(false);

            SemanticModel model = null;

            try
            {
                model = await document.GetSemanticModelAsync(_cancellationToken).ConfigureAwait(false);

                // start cache for this semantic model
                FindReferenceCache.Start(model);

#if PARALLEL
                Roslyn.Utilities.TaskExtensions.RethrowIncorrectAggregateExceptions(cancellationToken, () =>
                {
                    documentQueue.AsParallel().WithCancellation(cancellationToken).ForAll(symbolAndFinder =>
                    {
                        var symbol = symbolAndFinder.Item1;
                        var finder = symbolAndFinder.Item2;

                        ProcessDocument(document, symbol, finder, wrapper);
                    });
                });
#else
                foreach (var symbolAndFinder in documentQueue)
                {
                    var symbol = symbolAndFinder.Item1;
                    var finder = symbolAndFinder.Item2;

                    await ProcessDocumentAsync(document, symbol, finder, wrapper).ConfigureAwait(false);
                }
#endif
            }
            finally
            {
                FindReferenceCache.Stop(model);

                await _progress.OnFindInDocumentCompletedAsync(document).ConfigureAwait(false);
            }
        }