public override void Dispose() { BackgroundTagging?.Dispose(); ClassificationTagsCache?.Reset(); OutliningsTagsCache?.Reset(); base.Dispose(); }
/// <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); }
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); }
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); }