Changeset 8165 for trunk/sources/HeuristicLab.MainForm/3.3/Progress.cs
- Timestamp:
- 06/29/12 23:12:32 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm/3.3/Progress.cs
r8145 r8165 21 21 22 22 using System; 23 using HeuristicLab.Common; 23 24 24 25 namespace HeuristicLab.MainForm { … … 26 27 private string status; 27 28 public string Status { 28 get { 29 return this.status; 30 } 29 get { return status; } 31 30 set { 32 if ( this.status != value) {33 this.status = value;31 if (status != value) { 32 status = value; 34 33 OnStatusChanged(); 35 34 } … … 37 36 } 38 37 39 public bool CancelRequested { get; set; }40 41 38 private double progressValue; 42 39 public double ProgressValue { 43 get { 44 return this.progressValue; 45 } 40 get { return progressValue; } 46 41 set { 47 if ( this.progressValue != value) {48 this.progressValue = value;42 if (progressValue != value) { 43 progressValue = value; 49 44 OnProgressChanged(); 50 45 } … … 52 47 } 53 48 54 public Progress() { } 55 56 public Progress(string status) { 57 this.Status = status; 49 private ProgressState progressState; 50 public ProgressState ProgressState { 51 get { return progressState; } 52 set { 53 if (progressState != value) { 54 progressState = value; 55 OnProgressStateChanged(); 56 } 57 } 58 58 } 59 59 60 public void Finish() { 61 OnFinished(); 60 private bool canBeCanceled; 61 public bool CanBeCanceled { 62 get { return canBeCanceled; } 63 set { 64 if (canBeCanceled != value) { 65 canBeCanceled = value; 66 OnCanBeCanceledChanged(); 67 } 68 } 62 69 } 63 70 64 public void SignalSuccessfulCancelation() { 65 OnCanceled(); 71 public Progress() { 72 progressState = ProgressState.Started; 73 } 74 public Progress(string status) 75 : this() { 76 this.status = status; 77 } 78 public Progress(string status, double progressValue) 79 : this(status) { 80 this.progressValue = progressValue; 81 } 82 83 public void Cancel(int timeoutMs) { 84 if (canBeCanceled) 85 OnCancelRequested(timeoutMs); 86 } 87 88 /// <summary> 89 /// Sets the ProgressValue to 1 and the ProgressState to Finished. 90 /// </summary> 91 public void Finish() { 92 if (ProgressValue != 1.0) ProgressValue = 1.0; 93 ProgressState = ProgressState.Finished; 66 94 } 67 95 68 96 #region Event Handler 69 public event EventHandler Canceled;70 private void OnCanceled() {71 var handler = Canceled;72 try {73 if (handler != null) handler(this, EventArgs.Empty);74 }75 catch (Exception) { }76 }77 78 public event EventHandler Finished;79 private void OnFinished() {80 var handler = Finished;81 try {82 if (handler != null) handler(this, EventArgs.Empty);83 }84 catch (Exception) { }85 }86 87 97 public event EventHandler StatusChanged; 88 98 private void OnStatusChanged() { … … 90 100 try { 91 101 if (handler != null) handler(this, EventArgs.Empty); 92 } 93 catch (Exception) { } 102 } catch { } 94 103 } 95 104 … … 99 108 try { 100 109 if (handler != null) handler(this, EventArgs.Empty); 101 } 102 catch (Exception) { } 110 } catch { } 111 } 112 113 public event EventHandler ProgressStateChanged; 114 private void OnProgressStateChanged() { 115 var handler = ProgressStateChanged; 116 try { 117 if (handler != null) handler(this, EventArgs.Empty); 118 } catch { } 119 } 120 121 public event EventHandler CanBeCanceledChanged; 122 private void OnCanBeCanceledChanged() { 123 var handler = CanBeCanceledChanged; 124 try { 125 if (handler != null) handler(this, EventArgs.Empty); 126 } catch { } 127 } 128 129 public event EventHandler<EventArgs<int>> CancelRequested; 130 private void OnCancelRequested(int timeoutMs) { 131 var handler = CancelRequested; 132 try { 133 if (handler == null) throw new NotSupportedException("Cancel request was ignored."); 134 else handler(this, new EventArgs<int>(timeoutMs)); 135 } catch { } 103 136 } 104 137 #endregion
Note: See TracChangeset
for help on using the changeset viewer.