Beispiel #1
0
        private void LoadVolume(IBackgroundTaskContext context)
        {
            try
            {
                ProgressTask mainTask = new ProgressTask();
                mainTask.AddSubTask("BUILD", 90);
                mainTask.AddSubTask("LAYOUT", 10);

                context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, string.Format(SR.MessageInitializingMpr, mainTask.Progress)));

                BackgroundTaskParams @params = (BackgroundTaskParams)context.UserState;
                Volume volume = Volume.Create(@params.Frames,
                                              delegate(int i, int count)
                {
                    if (context.CancelRequested)
                    {
                        throw new BackgroundTaskCancelledException();
                    }
                    if (i == 0)
                    {
                        mainTask["BUILD"].AddSubTask("", count);
                    }
                    mainTask["BUILD"][""].Increment();
                    string message = string.Format(SR.MessageBuildingMprVolumeProgress, mainTask.Progress, i + 1, count, mainTask["BUILD"].Progress);
                    context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, message));
                });

                mainTask["BUILD"].MarkComplete();
                context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, string.Format(SR.MessagePerformingMprWorkspaceLayout, mainTask.Progress)));

                //call layout here b/c it could take a while
                @params.SynchronizationContext.Send(delegate
                {
                    _viewer = new MprViewerComponent(volume);
                    _viewer.Layout();
                }, null);

                mainTask["LAYOUT"].MarkComplete();
                context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, string.Format(SR.MessageDone, mainTask.Progress)));

                context.Complete();
            }
            catch (BackgroundTaskCancelledException)
            {
                context.Cancel();
            }
            catch (Exception ex)
            {
                context.Error(ex);
            }
        }