Ejemplo n.º 1
0
        public override void Dispose()
        {
            BackgroundTagging?.Dispose();
            ClassificationTagsCache?.Reset();
            OutliningsTagsCache?.Reset();

            base.Dispose();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the tags asynchronous in this collection.
        /// </summary>
        /// <param name="snapshot">The snapshot.</param>
        /// <returns>
        /// An enumerator that allows foreach to be used to process the tags asynchronous in this collection.
        /// </returns>
        protected virtual IEnumerable <ITagSpan <IClassificationTag> > GetTagsAsync(ITextSnapshot snapshot)
        {
            if (BackgroundTagging != null)
            {
                BackgroundTagging.CancelTagging();   //Cancel currently running task
                BackgroundTagging = null;
            }

            ResetCacheAndFlags(snapshot);
            BackgroundTagging = BackgroundTagging.StartBackgroundTagging(this);

            return(ClassificationTagsCache.ProcessedTags);
        }
Ejemplo n.º 3
0
        public static BackgroundTagging StartBackgroundTagging(PXColorizerTaggerBase tagger)
        {
            tagger.ThrowOnNull(nameof(tagger));

            BackgroundTagging backgroundTagging = new BackgroundTagging();

            backgroundTagging.TaggingTask = tagger.GetTagsAsyncImplementation(tagger.Snapshot, backgroundTagging.CancellationToken);
            backgroundTagging.TaggingTask?.ConfigureAwait(false);
            backgroundTagging.TaggingTask.ContinueWith(task => tagger.RaiseTagsChanged(),
                                                       backgroundTagging.CancellationToken,
                                                       TaskContinuationOptions.OnlyOnRanToCompletion,
                                                       TaskScheduler.Default)
            .ConfigureAwait(false);

            return(backgroundTagging);
        }
Ejemplo n.º 4
0
        public static BackgroundTagging StartBackgroundTagging(PXColorizerTaggerBase tagger)
        {
            tagger.ThrowOnNull(nameof(tagger));

            BackgroundTagging backgroundTagging = new BackgroundTagging();
            var taggingTask = tagger.GetTagsAsyncImplementationAsync(tagger.Snapshot, backgroundTagging.CancellationToken);

            if (taggingTask == null)
            {
                return(backgroundTagging);
            }

            // Use VS task scheduler from the VS synchronization context to schedule task continuation immediately to main thread
            // No need for synchronziation because FromCurrentSynchronizationContext creates schedulers which wrap around the same synchronization context
            // Therefore all schedulers should be identical and nothing wrong will happen if multiple threads create will create a scheduler
            _vsTaskScheduler = _vsTaskScheduler ?? TaskScheduler.FromCurrentSynchronizationContext();
            backgroundTagging.TaggingTask = taggingTask.ContinueWith(task => AfterTaggingActionAsync(tagger, backgroundTagging.CancellationToken),  //continuation should be on the UI thread
                                                                     backgroundTagging.CancellationToken,
                                                                     TaskContinuationOptions.OnlyOnRanToCompletion,
                                                                     _vsTaskScheduler);
            return(backgroundTagging);
        }