Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/29/12 23:12:32 (13 years ago)
Author:
abeham
Message:

#1762: Some changes to progress handling, see the ticket for more details

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/OptimizerHiveTaskView.cs

    r8160 r8165  
    3131  [Content(typeof(OptimizerHiveTask), true)]
    3232  public partial class OptimizerHiveTaskView : HiveTaskView {
    33     private ProgressView progressView;
    34     private IProgress progress;
     33    private Progress progress;
    3534
    3635    public new OptimizerHiveTask Content {
     
    4544    public OptimizerHiveTaskView() {
    4645      InitializeComponent();
    47       progressView = new ProgressView(this);
     46      progress = new Progress() {
     47        CanBeCanceled = false
     48      };
    4849    }
    4950
     
    7677      var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeTaskAsync);
    7778      task.ContinueWith((t) => {
    78         FinishProgressView();
     79        progress.Finish();
    7980        ErrorHandling.ShowErrorDialog(this, "An error occured while resuming the task.", t.Exception);
    8081      }, TaskContinuationOptions.OnlyOnFaulted);
     
    8485      var task = System.Threading.Tasks.Task.Factory.StartNew(PauseTaskAsync);
    8586      task.ContinueWith((t) => {
    86         FinishProgressView();
     87        progress.Finish();
    8788        ErrorHandling.ShowErrorDialog(this, "An error occured while pausing the task.", t.Exception);
    8889      }, TaskContinuationOptions.OnlyOnFaulted);
     
    9293      var task = System.Threading.Tasks.Task.Factory.StartNew(StopTaskAsync);
    9394      task.ContinueWith((t) => {
    94         FinishProgressView();
     95        progress.Finish();
    9596        ErrorHandling.ShowErrorDialog(this, "An error occured while stopping the task.", t.Exception);
    9697      }, TaskContinuationOptions.OnlyOnFaulted);
     
    99100
    100101    private void PauseTaskAsync() {
    101       progress = new Progress();
    102102      progress.Status = "Pausing task. Please be patient for the command to take effect.";
    103       SetProgressView(progress);
    104       Content.Pause();
    105       FinishProgressView();
     103      progress.ProgressState = ProgressState.Started;
     104      using (var view = new ProgressView(this, progress)) {
     105        Content.Pause();
     106      }
    106107    }
    107108
    108109    private void StopTaskAsync() {
    109       progress = new Progress();
    110110      progress.Status = "Stopping task. Please be patient for the command to take effect.";
    111       SetProgressView(progress);
    112       Content.Stop();
    113       FinishProgressView();
     111      progress.ProgressState = ProgressState.Started;
     112      using (var view = new ProgressView(this, progress)) {
     113        Content.Stop();
     114      }
    114115    }
    115116
    116117    private void ResumeTaskAsync() {
    117       progress = new Progress();
    118118      progress.Status = "Resuming task. Please be patient for the command to take effect.";
    119       SetProgressView(progress);
    120       Content.Restart();
    121       FinishProgressView();
    122     }
    123 
    124     private void SetProgressView(IProgress progress) {
    125       if (InvokeRequired) {
    126         Invoke(new Action<IProgress>(SetProgressView), progress);
    127       } else {
    128         progressView.Progress = progress;
    129       }
    130     }
    131 
    132     private void FinishProgressView() {
    133       if (InvokeRequired) {
    134         Invoke(new Action(FinishProgressView));
    135       } else {
    136         progress.Finish();
     119      progress.ProgressState = ProgressState.Started;
     120      using (var view = new ProgressView(this, progress)) {
     121        Content.Restart();
    137122      }
    138123    }
Note: See TracChangeset for help on using the changeset viewer.