Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/08/11 18:53:41 (13 years ago)
Author:
ascheibe
Message:

#1672 fixed starting, pausing and stopping of jobs and tasks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs

    r7068 r7156  
    3232using HeuristicLab.Optimization;
    3333using HeuristicLab.PluginInfrastructure;
     34using System.Threading.Tasks;
    3435
    3536namespace HeuristicLab.Clients.Hive.JobManager.Views {
     
    316317        SetEnabledStateOfControls();
    317318      }
    318     }
    319 
     319    }
    320320
    321321    private void UpdateStateLogList() {
     
    336336      if (nameTextBox.Text.Trim() == string.Empty) {
    337337        MessageBox.Show("Please enter a name for the job before uploading it!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
     338      } else if (Content.ExecutionState == ExecutionState.Paused) {             
     339        var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobAsync, Content);
     340        task.ContinueWith((t) => {
     341          FinishProgressView();
     342          MessageBox.Show("An error occured resuming the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
     343          Content.Log.LogException(t.Exception);
     344        }, TaskContinuationOptions.OnlyOnFaulted);
    338345      } else {
    339346        HiveClient.StartJob((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex), Content, new CancellationToken());
    340347      }
    341348    }
     349
    342350    private void pauseButton_Click(object sender, EventArgs e) {
    343       HiveClient.PauseJob(Content);
    344     }
     351      var task = System.Threading.Tasks.Task.Factory.StartNew(PauseJobAsync, Content);
     352      task.ContinueWith((t) => {       
     353        FinishProgressView();
     354        MessageBox.Show("An error occured pausing the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
     355        Content.Log.LogException(t.Exception);
     356      }, TaskContinuationOptions.OnlyOnFaulted);
     357    }         
     358
    345359    private void stopButton_Click(object sender, EventArgs e) {
    346       HiveClient.StopJob(Content);
     360      var task = System.Threading.Tasks.Task.Factory.StartNew(StopJobAsync, Content);
     361      task.ContinueWith((t) => {
     362        FinishProgressView();
     363        MessageBox.Show("An error occured stopping the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
     364        Content.Log.LogException(t.Exception);
     365      }, TaskContinuationOptions.OnlyOnFaulted);
    347366    }
    348367    private void resetButton_Click(object sender, EventArgs e) { }
     368
     369    private void PauseJobAsync(object job) {
     370      IProgress prog = new Progress();
     371      prog.Status = "Pausing job...";
     372      SetProgressView(prog);
     373      HiveClient.PauseJob((RefreshableJob)job);
     374      FinishProgressView();
     375    }
     376
     377    private void StopJobAsync(object job) {
     378      IProgress prog = new Progress();
     379      prog.Status = "Stopping job...";
     380      SetProgressView(prog);
     381      HiveClient.StopJob((RefreshableJob)job);
     382      FinishProgressView();
     383    }
     384
     385    private void ResumeJobAsync(object job) {
     386      IProgress prog = new Progress();
     387      prog.Status = "Resuming job...";
     388      SetProgressView(prog);
     389      HiveClient.ResumeJob((RefreshableJob)job);
     390      FinishProgressView();
     391    }
    349392
    350393    private void nameTextBox_Validated(object sender, EventArgs e) {
     
    385428      }
    386429    }
    387 
    388 
    389430    #endregion
    390431
     
    394435        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
    395436      } else {
    396         startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && Content.ExecutionState == ExecutionState.Prepared;
     437        startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused);
    397438        pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started;
    398439        stopButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started;
     
    416457
    417458    private void SetProgressView() {
    418       if (progressView == null) {
    419         progressView = new ProgressView(this, Content.Progress);
    420       }
    421       progressView.Progress = Content.Progress;
     459      if (InvokeRequired) {
     460        Invoke(new Action(SetProgressView));
     461      } else {
     462        if (progressView == null) {
     463          progressView = new ProgressView(this, Content.Progress);
     464        } else {
     465          progressView.Progress = Content.Progress;
     466        }
     467      }
     468    }
     469
     470    private void SetProgressView(IProgress progress) {
     471      if (InvokeRequired) {
     472        Invoke(new Action<IProgress>(SetProgressView), progress);
     473      } else {
     474        if (progressView == null) {
     475          progressView = new ProgressView(this, progress);
     476        } else {
     477          progressView.Progress = progress;
     478        }
     479      }
    422480    }
    423481
    424482    private void FinishProgressView() {
    425       if (progressView != null) {
    426         progressView.Finish();
    427         progressView = null;
    428         SetEnabledStateOfControls();
     483      if (InvokeRequired) {
     484        Invoke(new Action(FinishProgressView));
     485      } else {
     486        if (progressView != null) {
     487          progressView.Finish();
     488          progressView = null;
     489          SetEnabledStateOfControls();
     490        }
    429491      }
    430492    }
Note: See TracChangeset for help on using the changeset viewer.