public async Task DrainAsync() { while (true) // Keep draining until we're empty { JoinableTaskCollection joinableTasks = _joinableTaskContextNode.CreateCollection(); joinableTasks.DisplayName = GetType().FullName; var tasks = new List <Task>(); lock (_joinableTasks) { foreach (JoinableTask joinableTask in _joinableTasks) { joinableTasks.Add(joinableTask); tasks.Add(joinableTask.Task); } } if (tasks.Count == 0) { break; } // Let these tasks share the UI thread to avoid deadlocks in // case they need it while its blocked on this method. using (joinableTasks.Join()) { await Task.WhenAll(tasks) .ConfigureAwait(false); } } }
public SolutionRestoreWorker( IAsyncServiceProvider asyncServiceProvider, Lazy <IVsSolutionManager> solutionManager, Lazy <INuGetLockService> lockService, Lazy <Common.ILogger> logger, Lazy <INuGetErrorList> errorList, Lazy <IOutputConsoleProvider> outputConsoleProvider) { if (asyncServiceProvider == null) { throw new ArgumentNullException(nameof(asyncServiceProvider)); } if (solutionManager == null) { throw new ArgumentNullException(nameof(solutionManager)); } if (lockService == null) { throw new ArgumentNullException(nameof(lockService)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (errorList == null) { throw new ArgumentNullException(nameof(errorList)); } if (outputConsoleProvider == null) { throw new ArgumentNullException(nameof(outputConsoleProvider)); } _asyncServiceProvider = asyncServiceProvider; _solutionManager = solutionManager; _lockService = lockService; _logger = logger; _errorList = errorList; _outputConsoleProvider = outputConsoleProvider; var joinableTaskContextNode = new JoinableTaskContextNode(ThreadHelper.JoinableTaskContext); _joinableCollection = joinableTaskContextNode.CreateCollection(); JoinableTaskFactory = joinableTaskContextNode.CreateFactory(_joinableCollection); _componentModel = new AsyncLazy <IComponentModel>(async() => { return(await asyncServiceProvider.GetServiceAsync <SComponentModel, IComponentModel>()); }, JoinableTaskFactory); _solutionLoadedEvent = new AsyncManualResetEvent(); _isCompleteEvent = new AsyncManualResetEvent(); Reset(); }
public SolutionRestoreWorker( [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, Lazy <IVsSolutionManager> solutionManager, Lazy <INuGetLockService> lockService, [Import("VisualStudioActivityLogger")] Lazy <Common.ILogger> logger, Lazy <ErrorListTableDataSource> errorListTableDataSource) { if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } if (solutionManager == null) { throw new ArgumentNullException(nameof(solutionManager)); } if (lockService == null) { throw new ArgumentNullException(nameof(lockService)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (errorListTableDataSource == null) { throw new ArgumentNullException(nameof(errorListTableDataSource)); } _serviceProvider = serviceProvider; _solutionManager = solutionManager; _lockService = lockService; _logger = logger; _errorListTableDataSource = errorListTableDataSource; var joinableTaskContextNode = new JoinableTaskContextNode(ThreadHelper.JoinableTaskContext); _joinableCollection = joinableTaskContextNode.CreateCollection(); _joinableFactory = joinableTaskContextNode.CreateFactory(_joinableCollection); _componentModel = new AsyncLazy <IComponentModel>(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); return(serviceProvider.GetService <SComponentModel, IComponentModel>()); }, _joinableFactory); _solutionLoadedEvent = new AsyncManualResetEvent(); _isCompleteEvent = new AsyncManualResetEvent(); Reset(); }