Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/20/11 11:45:18 (12 years ago)
Author:
gkronber
Message:

#1081 merged r7103:7209 from trunk into time series branch

Location:
branches/HeuristicLab.TimeSeries
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries

  • branches/HeuristicLab.TimeSeries/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/OptimizerHiveTaskView.cs

    r6976 r7213  
    2323using System.Windows.Forms;
    2424using HeuristicLab.MainForm;
     25using System.Threading.Tasks;
     26using HeuristicLab.PluginInfrastructure;
    2527
    2628namespace HeuristicLab.Clients.Hive.Views {
     
    2830  [Content(typeof(OptimizerHiveTask), true)]
    2931  public partial class OptimizerHiveTaskView : HiveTaskView {
     32    private ProgressView progressView;
     33
    3034    public new OptimizerHiveTask Content {
    3135      get { return (OptimizerHiveTask)base.Content; }
     
    6771    #region Child Control Events
    6872    private void restartButton_Click(object sender, EventArgs e) {
    69       Content.Restart();
     73      var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeTaskAsync);
     74      task.ContinueWith((t) => {
     75        FinishProgressView();
     76        ErrorHandling.ShowErrorDialog(this, "An error occured while resuming the task.", t.Exception);
     77      }, TaskContinuationOptions.OnlyOnFaulted);
    7078    }
    7179
    7280    private void pauseButton_Click(object sender, EventArgs e) {
    73       Content.Pause();
     81      var task = System.Threading.Tasks.Task.Factory.StartNew(PauseTaskAsync);
     82      task.ContinueWith((t) => {
     83        FinishProgressView();
     84        ErrorHandling.ShowErrorDialog(this, "An error occured while pausing the task.", t.Exception);
     85      }, TaskContinuationOptions.OnlyOnFaulted);
    7486    }
    7587
    7688    private void stopButton_Click(object sender, EventArgs e) {
    77       Content.Stop();
     89      var task = System.Threading.Tasks.Task.Factory.StartNew(StopTaskAsync);
     90      task.ContinueWith((t) => {
     91        FinishProgressView();
     92        ErrorHandling.ShowErrorDialog(this, "An error occured while stopping the task.", t.Exception);
     93      }, TaskContinuationOptions.OnlyOnFaulted);
    7894    }
    7995    #endregion
     96
     97    private void PauseTaskAsync() {
     98      IProgress prog = new Progress();
     99      prog.Status = "Pausing task. Please be patient for the command to take effect.";
     100      SetProgressView(prog);
     101      Content.Pause();
     102      FinishProgressView();
     103    }
     104
     105    private void StopTaskAsync() {
     106      IProgress prog = new Progress();
     107      prog.Status = "Stopping task. Please be patient for the command to take effect.";
     108      SetProgressView(prog);
     109      Content.Stop();
     110      FinishProgressView();
     111    }
     112
     113    private void ResumeTaskAsync() {
     114      IProgress prog = new Progress();
     115      prog.Status = "Resuming task. Please be patient for the command to take effect.";
     116      SetProgressView(prog);
     117      Content.Restart();
     118      FinishProgressView();
     119    }
     120
     121    private void SetProgressView(IProgress progress) {
     122      if (InvokeRequired) {
     123        Invoke(new Action<IProgress>(SetProgressView), progress);
     124      } else {
     125        if (progressView == null) {
     126          progressView = new ProgressView(this, progress);
     127        } else {
     128          progressView.Progress = progress;
     129        }
     130      }
     131    }
     132
     133    private void FinishProgressView() {
     134      if (InvokeRequired) {
     135        Invoke(new Action(FinishProgressView));
     136      } else {
     137        if (progressView != null) {
     138          progressView.Finish();
     139          progressView = null;
     140          SetEnabledStateOfControls();
     141        }
     142      }
     143    }
    80144
    81145    protected override void SetEnabledStateOfControls() {
Note: See TracChangeset for help on using the changeset viewer.