- Timestamp:
- 12/08/11 18:53:41 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/OptimizerHiveTaskView.cs
r6976 r7156 23 23 using System.Windows.Forms; 24 24 using HeuristicLab.MainForm; 25 using System.Threading.Tasks; 26 using HeuristicLab.PluginInfrastructure; 25 27 26 28 namespace HeuristicLab.Clients.Hive.Views { … … 28 30 [Content(typeof(OptimizerHiveTask), true)] 29 31 public partial class OptimizerHiveTaskView : HiveTaskView { 32 private ProgressView progressView; 33 30 34 public new OptimizerHiveTask Content { 31 35 get { return (OptimizerHiveTask)base.Content; } … … 67 71 #region Child Control Events 68 72 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); 70 78 } 71 79 72 80 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); 74 86 } 75 87 76 88 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); 78 94 } 79 95 #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 } 80 144 81 145 protected override void SetEnabledStateOfControls() {
Note: See TracChangeset
for help on using the changeset viewer.