private void RunUpgrade() { var strategy = UserUpgradeStrategy.Create(); if (strategy == null) { return; } if (strategy.TotalSteps < 5 || null == (_dialogView = CreateDialog())) { strategy.Run(); return; } var task = new BackgroundTask( delegate(IBackgroundTaskContext context) { strategy.ProgressChanged += (sender, e) => context.ReportProgress(new BackgroundTaskProgress(strategy.CurrentStep - 1, strategy.TotalSteps, String.Empty)); strategy.Run(); context.Complete(); }, false, strategy); task.ProgressUpdated += (sender, e) => _dialogView.SetProgressPercent(e.Progress.Percent); task.Terminated += (sender, e) => _dialogView.Close(strategy.FailedCount > 0 ? SR.MessageUserUpgradeFailures : null); task.Run(); _dialogView.RunModal(SR.TitleUpdatingPreferences, SR.MessageUpdatingPreferences); task.Dispose(); }
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e) { // No idea which of these are triggering on rare occasions, perhaps Deactivate, sizechanged or filterWindow. FormClosing -= MainWindow_FormClosing; SizeChanged -= OnMinimizeWindow; _stashFileMonitor?.Dispose(); _stashFileMonitor = null; _minimizeToTrayHandler?.Dispose(); _minimizeToTrayHandler = null; _backupBackgroundTask?.Dispose(); _usageStatisticsReporter.Dispose(); _automaticUpdateChecker.Dispose(); _tooltipHelper?.Dispose(); _buddyItemsService?.Dispose(); _buddyItemsService = null; _injector?.Dispose(); _injector = null; _backupServiceWorker?.Dispose(); _backupServiceWorker = null; _window?.Dispose(); _window = null; IterAndCloseForms(Controls); }
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e) { // No idea which of these are triggering on rare occasions, perhaps Deactivate, sizechanged or filterWindow. FormClosing -= MainWindow_FormClosing; SizeChanged -= OnMinimizeWindow; _stashFileMonitor?.Dispose(); _stashFileMonitor = null; _stashManager = null; _backupBackgroundTask?.Dispose(); _timerReportUsage?.Stop(); _timerReportUsage?.Dispose(); _timerReportUsage = null; _tooltipHelper?.Dispose(); _buddyBackgroundThread?.Dispose(); _buddyBackgroundThread = null; panelHelp.Controls.Clear(); _injector?.Dispose(); _injector = null; _backupServiceWorker?.Dispose(); _backupServiceWorker = null; _window?.Dispose(); _window = null; IterAndCloseForms(Controls); }
public void ChangeToSyntax(TransferSyntax syntax) { _syntax = syntax; BackgroundTask task = null; try { task = new BackgroundTask(ChangeToSyntax, false, Context.SelectedStudy); ProgressDialog.Show(task, this.Context.DesktopWindow, true); } catch (Exception e) { Platform.Log(LogLevel.Error, e); string message = String.Format("An error occurred while compressing; folder must be deleted manually: {0}", _tempPath); this.Context.DesktopWindow.ShowMessageBox(message, MessageBoxActions.Ok); } finally { _tempPath = null; if (task != null) { task.Dispose(); } } }
public void AnonymizeStudy() { _component = new AnonymizeStudyComponent(Context.SelectedStudy); if (ApplicationComponentExitCode.Accepted == ApplicationComponent.LaunchAsDialog(Context.DesktopWindow, _component, SR.TitleAnonymizeStudy)) { if (LocalStorageMonitor.IsMaxUsedSpaceExceeded) { Context.DesktopWindow.ShowMessageBox(SR.MessageCannotAnonymizeMaxDiskUsageExceeded, MessageBoxActions.Ok); return; } BackgroundTask task = null; try { task = new BackgroundTask(Anonymize, false, Context.SelectedStudy); ProgressDialog.Show(task, Context.DesktopWindow, true); } catch (Exception e) { Platform.Log(LogLevel.Error, e); Context.DesktopWindow.ShowMessageBox(SR.MessageAnonymizeStudyFailed, MessageBoxActions.Ok); } finally { if (task != null) { task.Dispose(); } } } }
public void RenameStudy() { _component = new RenameStudyComponent(this.Context.SelectedStudy); if (ApplicationComponentExitCode.Accepted == ApplicationComponent.LaunchAsDialog(this.Context.DesktopWindow, _component, "Rename Study")) { BackgroundTask task = null; try { task = new BackgroundTask(Rename, false, this.Context.SelectedStudy.StudyInstanceUid); ProgressDialog.Show(task, this.Context.DesktopWindow, true); } catch (Exception e) { Platform.Log(LogLevel.Error, e); string message = String.Format("Must Delete Manually", _tempPath); this.Context.DesktopWindow.ShowMessageBox(message, MessageBoxActions.Ok); } finally { _tempPath = null; if (task != null) { task.Dispose(); } } } }
private void Export() { if (DisplaySet.PresentationImages.Count <= 10) { ExportImages(null); Cleanup(); } else { BackgroundTask task = new BackgroundTask(ExportImages, true) { ThreadUICulture = Application.CurrentUICulture }; _clipboardItem.Lock(); ProgressDialogComponent progressComponent = new ProgressDialogComponent(task, true, ProgressBarStyle.Blocks); _progressComponentShelf = ApplicationComponent.LaunchAsShelf(this.Host.DesktopWindow, progressComponent, SR.TitleCreatingVideo, "CreatingVideo", ShelfDisplayHint.DockFloat); _progressComponentShelf.Closed += delegate { _clipboardItem.Unlock(); Cleanup(); task.Dispose(); }; } }
public void Run() { CreateBaseDataSet(); _tempFileDirectory = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "ClearCanvas"); _tempFileDirectory = System.IO.Path.Combine(_tempFileDirectory, "BitmapImport"); DeleteEmptyFolders(_tempFileDirectory); _tempFileDirectory = System.IO.Path.Combine(_tempFileDirectory, System.IO.Path.GetRandomFileName()); Directory.CreateDirectory(_tempFileDirectory); BackgroundTask task = new BackgroundTask(Process, true); task.Terminated += delegate { OnComplete(); task.Dispose(); }; lock (_waitShowProgressLock) { task.Run(); Monitor.Wait(_waitShowProgressLock); if (_showProgress) { ProgressDialogComponent progressComponent = new ProgressDialogComponent(task, true, ProgressBarStyle.Blocks); LaunchAsShelf(DesktopWindow, progressComponent, SR.TitleImportingImages, ShelfDisplayHint.DockFloat); } Monitor.Pulse(_waitShowProgressLock); } }
public void Run() { if (NumberOfImagesToExport <= 5) { BlockingOperation.Run(delegate { Export(null); }); Complete(); } else { ItemsToExport.ForEach(delegate(IClipboardItem item) { item.Lock(); }); BackgroundTask task = new BackgroundTask(Export, true) { ThreadUICulture = Application.CurrentUICulture }; ProgressDialogComponent progressComponent = new ProgressDialogComponent(task, true, ProgressBarStyle.Blocks); _progressComponentShelf = LaunchAsShelf(DesktopWindow, progressComponent, SR.TitleExportingImages, "ExportingImages", ShelfDisplayHint.DockFloat); _progressComponentShelf.Closed += delegate { Complete(); task.Dispose(); }; } }
private void OnTaskTerminated(object sender, BackgroundTaskTerminatedEventArgs e) { BackgroundTask updateTask = sender as BackgroundTask; if (updateTask != null) { updateTask.Terminated -= OnTaskTerminated; updateTask.Dispose(); } _updateTask = null; }
/// <summary> /// Causes any pending asynchronous execution to be discarded (the continuation/error handler will not be called). /// </summary> public void Cancel() { if (_backgroundTask != null) { _continuationCode = null; _errorHandler = null; _backgroundTask.Terminated -= TerminatedEventHandler; _backgroundTask.Dispose(); _backgroundTask = null; } }
private void OnVolumeLoaderTaskTerminated(object sender, BackgroundTaskTerminatedEventArgs e) { BackgroundTask volumeLoaderTask = sender as BackgroundTask; if (volumeLoaderTask != null) { volumeLoaderTask.Terminated -= OnVolumeLoaderTaskTerminated; volumeLoaderTask.Dispose(); } _volumeLoaderTask = null; }
private void ShelfClose(object Sender, ClosedEventArgs args) { _desktopWindow.Closing -= DesktopWindowsClose; _shelf.Closed -= ShelfClose; if (_task.IsRunning) { _task.RequestCancel(); } _task.Dispose(); _task = null; _shelf = null; EventsHelper.Fire(_closeShelf, this, null); }
private bool SendAnnotationsToGrid(List <aim_dotnet.Annotation> annotations) { if (annotations == null || annotations.Count == 0) { return(true); } var xmlAnnotations = new Dictionary <string, string>(); var xmlModel = new XmlModel(); foreach (var annotation in annotations) { try { xmlAnnotations.Add(annotation.UniqueIdentifier, xmlModel.WriteAnnotationToXmlString(annotation)); } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to convert annotation to xml."); } } xmlModel = null; // Send Annotations to AIM Service if (xmlAnnotations.Count > 0) { BackgroundTask task = null; try { task = new BackgroundTask(BackgroundSendAnnotationsToAimService, false, xmlAnnotations); ProgressDialog.Show(task, DesktopWindow, true); return(true); } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Failed to send annotation(s) to the AIM data service"); DesktopWindow.ShowMessageBox("Failed to send annotation(s) to the AIM data service. See log for details.", MessageBoxActions.Ok); } finally { if (task != null) { task.Dispose(); } } } return(false); }
private void OnVolumeLoaderTaskTerminated(object sender, BackgroundTaskTerminatedEventArgs e) { // TODO (CR Apr 2013): Since BeginLoad is only ever triggered from the UI thread (Draw), this won't be // a problem because the task's Terminated event will also be fired on the UI thread. If the task // were not created on the UI thread, though, this would have to be inside a lock (_syncLoaderLock). BackgroundTask volumeLoaderTask = sender as BackgroundTask; if (volumeLoaderTask != null) { volumeLoaderTask.Terminated -= OnVolumeLoaderTaskTerminated; volumeLoaderTask.Dispose(); } _volumeLoaderTask = null; }
protected virtual void Dispose(bool disposing) { Interlocked.Exchange(ref _disposed, 1); if (TextBuffer != null) { TextBuffer.Changed -= OnTextBufferChanged; TextBuffer = null; } if (BackgroundTask != null) { BackgroundTask.Dispose(); BackgroundTask = null; } }
public void LaunchMpr() { Exception exception = null; IPresentationImage currentImage = this.Context.Viewer.SelectedPresentationImage; if (currentImage == null) { return; } // gather the source frames which MPR will operate on. exceptions are reported. BackgroundTaskParams @params; try { @params = new BackgroundTaskParams(FilterSourceFrames(currentImage.ParentDisplaySet, currentImage)); } catch (Exception ex) { ExceptionHandler.Report(ex, SR.ExceptionMprLoadFailure, base.Context.DesktopWindow); return; } // execute the task to create an MPR component. exceptions (either thrown or passed via task) are reported, but any created component must be disposed BackgroundTask task = new BackgroundTask(LoadVolume, true, @params); task.Terminated += (sender, e) => exception = e.Exception; try { ProgressDialog.Show(task, base.Context.DesktopWindow, true, ProgressBarStyle.Blocks); } catch (Exception ex) { exception = ex; if (_viewer != null) { _viewer.Dispose(); _viewer = null; } } finally { task.Dispose(); } if (exception != null) { ExceptionHandler.Report(exception, SR.ExceptionMprLoadFailure, base.Context.DesktopWindow); return; } // launch the created MPR component as a workspace. any exceptions here are just reported. try { LaunchImageViewerArgs args = new LaunchImageViewerArgs(ViewerLaunchSettings.WindowBehaviour); args.Title = _viewer.Title; MprViewerComponent.Launch(_viewer, args); } catch (Exception ex) { ExceptionHandler.Report(ex, SR.ExceptionMprLoadFailure, base.Context.DesktopWindow); } finally { _viewer = null; } }