示例#1
0
 internal static void WaitForBackgroundToComplete <TData, TTag>(this AsyncTagger <TData, TTag> asyncTagger, TestableSynchronizationContext synchronizationContext)
     where TTag : ITag
 {
     while (asyncTagger.AsyncBackgroundRequestData.HasValue)
     {
         synchronizationContext.RunAll();
         Thread.Yield();
     }
 }
示例#2
0
            public void GetTags()
            {
                Create("dog", "cat", "fish", "dog");
                _asyncTaggerSource.SetBackgroundFunc(span => TestUtils.GetDogTags(span));
                _asyncTagger.GetTags(_textBuffer.GetLineRange(0).Extent);
                Assert.True(_asyncTagger.AsyncBackgroundRequestData.HasValue);

                // Background is done.  Because we control the synchronization context though the foreground
                // thread still sees it as active and hence will continue to queue data on it
                _asyncTagger.AsyncBackgroundRequestData.Value.Task.Wait();
                Assert.True(_asyncTagger.AsyncBackgroundRequestData.HasValue);
                _asyncTagger.GetTags(_textBuffer.GetLineRange(3).Extent);

                // Clear the queue, the missing work will be seen and immedieatly requeued
                TestableSynchronizationContext.RunAll();
                Assert.True(_asyncTagger.AsyncBackgroundRequestData.HasValue);
                WaitForBackgroundToComplete();

                var tags = _asyncTagger.GetTags(_textBuffer.GetExtent());

                Assert.Equal(
                    new[] { _textBuffer.GetLineSpan(0, 3), _textBuffer.GetLineSpan(3, 3) },
                    tags.Select(x => x.Span));
            }