public async Task ReleaseProjectContextAsync(AggregateWorkspaceProjectContext context)
        {
            Requires.NotNull(context, nameof(context));

            ImmutableHashSet <IWorkspaceProjectContext> usedProjectContexts;

            lock (_gate)
            {
                if (!_contexts.Remove(context))
                {
                    throw new ArgumentException("Specified context was not created by this instance, or has already been unregistered.");
                }

                // Update the maps storing configured project host objects and project contexts which are shared across created contexts.
                // We can remove the ones which are only used by the current context being released.
                RemoveUnusedConfiguredProjectsState_NoLock();

                usedProjectContexts = _configuredProjectContextsMap.Values.ToImmutableHashSet();
            }

            // TODO: https://github.com/dotnet/roslyn-project-system/issues/353
            await _commonServices.ThreadingService.SwitchToUIThread();

            // We don't want to dispose the inner workspace contexts that are still being used by other active aggregate contexts.
            Func <IWorkspaceProjectContext, bool> shouldDisposeInnerContext = c => !usedProjectContexts.Contains(c);

            context.Dispose(shouldDisposeInnerContext);
        }
Пример #2
0
        public async Task <AggregateWorkspaceProjectContext> CreateProjectContextAsync()
        {
            EnsureInitialized();

            AggregateWorkspaceProjectContext context = await CreateProjectContextAsyncCore().ConfigureAwait(false);

            if (context == null)
            {
                return(null);
            }

            lock (_gate)
            {
                // There's a race here, by the time we've created the project context,
                // the project could have been renamed, handle this.
                ProjectData projectData = GetProjectData();

                context.SetProjectFilePathAndDisplayName(projectData.FullPath, projectData.DisplayName);
                _contexts.Add(context);
            }

            return(context);
        }