void RunActionsWithProgressMonitor(
     ProgressMonitorStatusMessage progressMessage,
     IList <IPackageAction> installPackageActions,
     TaskCompletionSource <bool> taskCompletionSource,
     bool clearConsole,
     CancellationTokenSource cancellationTokenSource)
 {
     using (ProgressMonitor monitor = progressMonitorFactory.CreateProgressMonitor(progressMessage.Status, clearConsole, cancellationTokenSource)) {
         using (PackageManagementEventsMonitor eventMonitor = CreateEventMonitor(monitor, taskCompletionSource)) {
             try {
                 monitor.BeginTask(null, installPackageActions.Count);
                 RunActionsWithProgressMonitor(monitor, installPackageActions);
                 eventMonitor.ReportResult(progressMessage);
             } catch (Exception ex) {
                 RemoveInstallActions(installPackageActions);
                 bool showPackageConsole = !monitor.CancellationToken.IsCancellationRequested;
                 eventMonitor.ReportError(progressMessage, ex, showPackageConsole);
             } finally {
                 monitor.EndTask();
                 GuiDispatch(() => {
                     RemoveInstallActions(installPackageActions);
                     packageManagementEvents.OnPackageOperationsFinished();
                 });
             }
         }
     }
 }
        public void Dispose()
        {
            packageManagementEvents.OnPackageOperationsFinished();

            packageManagementEvents.PackageOperationMessageLogged -= PackageOperationMessageLogged;
            packageManagementEvents.FileChanged -= FileChanged;
            NotifyFilesChanged();
        }
 void RunActionsWithProgressMonitor(ProgressMonitorStatusMessage progressMessage, IList <IPackageAction> installPackageActions)
 {
     using (IProgressMonitor monitor = progressMonitorFactory.CreateProgressMonitor(progressMessage.Status)) {
         using (PackageManagementEventsMonitor eventMonitor = CreateEventMonitor(monitor)) {
             try {
                 monitor.BeginTask(null, installPackageActions.Count);
                 RunActionsWithProgressMonitor(monitor, installPackageActions);
                 eventMonitor.ReportResult(progressMessage);
             } catch (Exception ex) {
                 RemoveInstallActions(installPackageActions);
                 eventMonitor.ReportError(progressMessage, ex);
             } finally {
                 monitor.EndTask();
                 GuiDispatch(() => {
                     RemoveInstallActions(installPackageActions);
                     packageManagementEvents.OnPackageOperationsFinished();
                 });
             }
         }
     }
 }
 public void OnPackageOperationsFinished()
 {
     unsafeEvents.OnPackageOperationsFinished();
 }