public RunningDocumentTableEventTracker( IThreadingContext threadingContext, IVsEditorAdaptersFactoryService editorAdaptersFactoryService, IVsRunningDocumentTable runningDocumentTable, IRunningDocumentTableEventListener listener ) { Contract.ThrowIfNull(threadingContext); Contract.ThrowIfNull(editorAdaptersFactoryService); Contract.ThrowIfNull(runningDocumentTable); Contract.ThrowIfNull(listener); _foregroundAffinitization = new ForegroundThreadAffinitizedObject( threadingContext, assertIsForeground: false ); _runningDocumentTable = (IVsRunningDocumentTable4)runningDocumentTable; _editorAdaptersFactoryService = editorAdaptersFactoryService; _listener = listener; // Advise / Unadvise for the RDT is free threaded past 16.0 ((IVsRunningDocumentTable)_runningDocumentTable).AdviseRunningDocTableEvents( this, out _runningDocumentTableEventsCookie ); }
public async Task TestForegroundThread(bool inBg) { var context = CompositionManager.Instance.GetExportedValue <IThreadingContext> (); var obj = new ForegroundThreadAffinitizedObject(context, false); var roslynContext = obj.ThreadingContext.JoinableTaskContext; Assert.AreSame(Runtime.MainThread, roslynContext.MainThread); Assert.IsTrue(obj.IsForeground()); await Task.Run(() => { Assert.IsFalse(obj.IsForeground()); }); int x = 0; await obj.InvokeBelowInputPriorityAsync(() => { Assert.IsTrue(obj.IsForeground()); x++; }); Assert.AreEqual(1, x); await Task.Run(() => obj.InvokeBelowInputPriorityAsync(() => { Assert.IsTrue(obj.IsForeground()); x++; })); Assert.AreEqual(2, x); }
public InlineHintsTagger( InlineHintsTaggerProvider taggerProvider, IWpfTextView textView, ITextBuffer buffer, ITagAggregator <InlineHintDataTag> tagAggregator ) { _cache = new List <ITagSpan <IntraTextAdornmentTag> >(); _threadAffinitizedObject = new ForegroundThreadAffinitizedObject( taggerProvider.ThreadingContext ); _taggerProvider = taggerProvider; _textView = textView; _buffer = buffer; _tagAggregator = tagAggregator; _formatMap = taggerProvider.ClassificationFormatMapService.GetClassificationFormatMap( textView ); _hintClassification = taggerProvider.ClassificationTypeRegistryService.GetClassificationType( InlineHintsTag.TagId ); _formatMap.ClassificationFormatMappingChanged += this.OnClassificationFormatMappingChanged; _tagAggregator.TagsChanged += OnTagAggregatorTagsChanged; }
public ViewSpanChangedEventSource(IThreadingContext threadingContext, ITextView textView, TaggerDelay textChangeDelay, TaggerDelay scrollChangeDelay) { Debug.Assert(textView != null); _foregroundObject = new ForegroundThreadAffinitizedObject(threadingContext); _textView = textView; _textChangeDelay = textChangeDelay; _scrollChangeDelay = scrollChangeDelay; }
private OpenFileTracker(VisualStudioWorkspaceImpl workspace, IVsRunningDocumentTable4 runningDocumentTable, IComponentModel componentModel) { _workspace = workspace; _foregroundAffinitization = new ForegroundThreadAffinitizedObject(workspace._threadingContext, assertIsForeground: true); _runningDocumentTable = runningDocumentTable; _editorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>(); _asyncOperationListener = componentModel.GetService <IAsynchronousOperationListenerProvider>().GetListener(FeatureAttribute.Workspace); }
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true); await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var componentModel = (IComponentModel) await GetServiceAsync(typeof(SComponentModel)); ForegroundObject = new ForegroundThreadAffinitizedObject(componentModel.GetService <IThreadingContext>()); }
protected override void Initialize() { base.Initialize(); // Assume that we are being initialized on the UI thread at this point. var defaultForegroundThreadData = ForegroundThreadData.CreateDefault( defaultKind: ForegroundThreadDataKind.ForcedByPackageInitialize); ForegroundThreadAffinitizedObject.CurrentForegroundThreadData = defaultForegroundThreadData; ForegroundObject = new ForegroundThreadAffinitizedObject(); }
protected override void Initialize() { base.Initialize(); var defaultForegroundThreadData = ForegroundThreadData.CreateDefault(); ForegroundThreadAffinitizedObject.DefaultForegroundThreadData = defaultForegroundThreadData; _foregroundObject = new ForegroundThreadAffinitizedObject(defaultForegroundThreadData); foreach (var editorFactory in CreateEditorFactories()) { RegisterEditorFactory(editorFactory); } RegisterLanguageService(typeof(TLanguageService), () => { // Create the language service, tell it to set itself up, then store it in a field // so we can notify it that it's time to clean up. _languageService = CreateLanguageService(); _languageService.Setup(); return(_languageService.ComAggregate); }); // Okay, this is also a bit strange. We need to get our Interop dll into our process, // but we're in the GAC. Ask the base Roslyn Package to load, and it will take care of // it for us. // * NOTE * workspace should never be created before loading roslyn package since roslyn package // installs a service roslyn visual studio workspace requires IVsPackage setupPackage; var shell = (IVsShell)this.GetService(typeof(SVsShell)); shell.LoadPackage(Guids.RoslynPackageId, out setupPackage); _miscellaneousFilesWorkspace = this.ComponentModel.GetService <MiscellaneousFilesWorkspace>(); if (_miscellaneousFilesWorkspace != null) { // make sure solution crawler start once everything has been setup. _miscellaneousFilesWorkspace.StartSolutionCrawler(); } RegisterMiscellaneousFilesWorkspaceInformation(_miscellaneousFilesWorkspace); this.Workspace = this.CreateWorkspace(); if (this.Workspace != null) { // make sure solution crawler start once everything has been setup. // this also should be started before any of workspace events start firing this.Workspace.StartSolutionCrawler(); } // Ensure services that must be created on the UI thread have been. HACK_AbstractCreateServicesOnUiThread.CreateServicesOnUIThread(ComponentModel, RoslynLanguageName); }
protected ZWindow(ZWindowManager manager, FontAndColorService fontAndColorService) { this.Manager = manager; this.fontAndColorService = fontAndColorService; this.foregroundThreadAffinitizedObject = new ForegroundThreadAffinitizedObject(); UseLayoutRounding = true; SnapsToDevicePixels = true; TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display); TextOptions.SetTextRenderingMode(this, TextRenderingMode.Auto); }
private ScreenViewModel(GameService gameService, FontAndColorService fontAndColorService) : base("Views/ScreenView") { this.foregroundThreadAffinitedObject = new ForegroundThreadAffinitizedObject(); this.gameService = gameService; this.fontAndColorService = fontAndColorService; this.windowManager = new ZWindowManager(fontAndColorService); this.gameService.GameOpened += OnGameOpened; this.gameService.GameClosing += OnGameClosing; }
public void QueueCheckForFilesBeingOpen(ImmutableArray <string> newFileNames) { ForegroundThreadAffinitizedObject.ThisCanBeCalledOnAnyThread(); var shouldStartTask = false; lock (_gate) { // If we've already decided to enumerate the full table, nothing further to do. if (!_justEnumerateTheEntireRunningDocumentTable) { // If this is going to push us over our threshold for scanning the entire table then just give up if ((_fileNamesToCheckForOpenDocuments?.Count ?? 0) + newFileNames.Length > CutoffForCheckingAllRunningDocumentTableDocuments) { _fileNamesToCheckForOpenDocuments = null; _justEnumerateTheEntireRunningDocumentTable = true; } else { if (_fileNamesToCheckForOpenDocuments == null) { _fileNamesToCheckForOpenDocuments = new HashSet <string>(newFileNames); } else { foreach (var filename in newFileNames) { _fileNamesToCheckForOpenDocuments.Add(filename); } } } } if (!_taskPending) { _taskPending = true; shouldStartTask = true; } } if (shouldStartTask) { var asyncToken = _asyncOperationListener.BeginAsyncOperation(nameof(QueueCheckForFilesBeingOpen)); Task.Run(async() => { await _foregroundAffinitization.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(); ProcessQueuedWorkOnUIThread(); }).CompletesAsyncOperation(asyncToken); } }
protected override void Initialize() { base.Initialize(); // Assume that we are being initialized on the UI thread at this point, and setup our foreground state var kind = ForegroundThreadDataInfo.CreateDefault(ForegroundThreadDataKind.ForcedByPackageInitialize); // None of the work posted to the foregroundTaskScheduler should block pending keyboard/mouse input from the user. // So instead of using the default priority which is above user input, we use Background priority which is 1 level // below user input. var taskScheduler = new SynchronizationContextTaskScheduler(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher, DispatcherPriority.Background)); ForegroundThreadAffinitizedObject.CurrentForegroundThreadData = new ForegroundThreadData(Thread.CurrentThread, taskScheduler, kind); ForegroundObject = new ForegroundThreadAffinitizedObject(); }
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true); await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); // Assume that we are being initialized on the UI thread at this point, and setup our foreground state var kind = ForegroundThreadDataInfo.CreateDefault(ForegroundThreadDataKind.ForcedByPackageInitialize); // None of the work posted to the foregroundTaskScheduler should block pending keyboard/mouse input from the user. // So instead of using the default priority which is above user input, we use Background priority which is 1 level // below user input. var taskScheduler = new SynchronizationContextTaskScheduler(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher, DispatcherPriority.Background)); ForegroundThreadAffinitizedObject.CurrentForegroundThreadData = new ForegroundThreadData(Thread.CurrentThread, taskScheduler, kind); ForegroundObject = new ForegroundThreadAffinitizedObject(); }
/// <summary> /// Reset the thread affinity, in particular the designated foreground thread, to the active /// thread. /// </summary> public static void ResetThreadAffinity() { ForegroundThreadAffinitizedObject.Initialize(force: true); // HACK: When the platform team took over several of our components they created a copy // of ForegroundThreadAffinitizedObject. This needs to be reset in the same way as our copy // does. Reflection is the only choice at the moment. foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies()) { var type = assembly.GetType("Microsoft.VisualStudio.Language.Intellisense.Implementation.ForegroundThreadAffinitizedObject", throwOnError: false); if (type != null) { type.GetField("foregroundThread", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, ForegroundThreadAffinitizedObject.ForegroundThread); type.GetField("ForegroundTaskScheduler", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, ForegroundThreadAffinitizedObject.ForegroundTaskScheduler); break; } } }
protected override void Initialize() { base.Initialize(); ForegroundThreadAffinitizedObject.Initialize(); FatalError.Handler = FailFast.OnFatalException; FatalError.NonFatalHandler = WatsonReporter.Report; // We also must set the FailFast handler for the compiler layer as well var compilerAssembly = typeof(Compilation).Assembly; var compilerFatalError = compilerAssembly.GetType("Microsoft.CodeAnalysis.FatalError", throwOnError: true); var property = compilerFatalError.GetProperty(nameof(FatalError.Handler), BindingFlags.Static | BindingFlags.Public); var compilerFailFast = compilerAssembly.GetType(typeof(FailFast).FullName, throwOnError: true); var method = compilerFailFast.GetMethod(nameof(FailFast.OnFatalException), BindingFlags.Static | BindingFlags.NonPublic); property.SetValue(null, Delegate.CreateDelegate(property.PropertyType, method)); InitializePortableShim(compilerAssembly); RegisterFindResultsLibraryManager(); var componentModel = (IComponentModel)this.GetService(typeof(SComponentModel)); _workspace = componentModel.GetService <VisualStudioWorkspace>(); var telemetrySetupExtensions = componentModel.GetExtensions <IRoslynTelemetrySetup>(); foreach (var telemetrySetup in telemetrySetupExtensions) { telemetrySetup.Initialize(this); } // set workspace output pane _outputPane = new WorkspaceFailureOutputPane(this, _workspace); InitializeColors(); // load some services that have to be loaded in UI thread LoadComponentsInUIContext(); _solutionEventMonitor = new SolutionEventMonitor(_workspace); }
public async Task TestForegroundThread(bool initAgain, bool inBg) { if (initAgain) { var current = ForegroundThreadAffinitizedObject.CurrentForegroundThreadData; if (inBg) { await Task.Run(() => { RoslynService.Initialize(); }); } else { RoslynService.Initialize(); } Assert.AreSame(current, ForegroundThreadAffinitizedObject.CurrentForegroundThreadData); } var obj = new ForegroundThreadAffinitizedObject(false); // FIXME: Roslyn does not about Xwt Synchronization context. //Assert.AreEqual (ForegroundThreadDataKind.MonoDevelopGtk, obj.ForegroundKind); Assert.AreEqual(Runtime.MainTaskScheduler, obj.ForegroundTaskScheduler); Assert.IsTrue(obj.IsForeground()); await Task.Run(() => { Assert.IsFalse(obj.IsForeground()); }); int x = 0; await obj.InvokeBelowInputPriority(() => { Assert.IsTrue(obj.IsForeground()); x++; }); Assert.AreEqual(1, x); await Task.Run(() => obj.InvokeBelowInputPriority(() => { Assert.IsTrue(obj.IsForeground()); x++; })); Assert.AreEqual(2, x); }
public MiscellaneousFilesWorkspace( IVsEditorAdaptersFactoryService editorAdaptersFactoryService, IMetadataAsSourceFileService fileTrackingMetadataAsSourceService, SaveEventsService saveEventsService, VisualStudioWorkspace visualStudioWorkspace, SVsServiceProvider serviceProvider) : base(visualStudioWorkspace.Services.HostServices, WorkspaceKind.MiscellaneousFiles) { _foregroundThreadAffinitization = new ForegroundThreadAffinitizedObject(assertIsForeground: true); _editorAdaptersFactoryService = editorAdaptersFactoryService; _fileTrackingMetadataAsSourceService = fileTrackingMetadataAsSourceService; _runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable)); _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); ((IVsRunningDocumentTable)_runningDocumentTable).AdviseRunningDocTableEvents(this, out _runningDocumentTableEventsCookie); _metadataReferences = ImmutableArray.CreateRange(CreateMetadataReferences()); _documentProvider = new DocumentProvider(this, serviceProvider, documentTrackingService: null); saveEventsService.StartSendingSaveEvents(); }
public ViewSpanChangedEventSource(IThreadingContext threadingContext, ITextView textView) { Debug.Assert(textView != null); _foregroundObject = new ForegroundThreadAffinitizedObject(threadingContext); _textView = textView; }