comparison Implab/TaskController.cs @ 12:eb418ba8275b promises

refactoring, added WorkerPool
author cin
date Tue, 05 Nov 2013 19:55:34 +0400
parents aa33d0bb8c0c
children 9bf5b23650c9
comparison
equal deleted inserted replaced
11:6ec82bf68c8e 12:eb418ba8275b
10 /// This class allows to interact with asyncronuos task. 10 /// This class allows to interact with asyncronuos task.
11 /// </summary> 11 /// </summary>
12 /// <remarks> 12 /// <remarks>
13 /// Members of this object are thread safe. 13 /// Members of this object are thread safe.
14 /// </remarks> 14 /// </remarks>
15 class TaskController 15 class TaskController: IProgressNotifier, ITaskController, ICancellable
16 { 16 {
17 readonly object m_lock; 17 readonly object m_lock;
18 string m_message; 18 string m_message;
19 19
20 float m_current; 20 float m_current;
21 float m_max; 21 float m_max;
22
23 bool m_cancelled;
22 24
23 public event EventHandler<ValueEventArgs<string>> MessageUpdated; 25 public event EventHandler<ValueEventArgs<string>> MessageUpdated;
24 public event EventHandler<ValueEventArgs<float>> ProgressUpdated; 26 public event EventHandler<ValueEventArgs<float>> ProgressUpdated;
25 public event EventHandler<ProgressInitEventArgs> ProgressInit; 27 public event EventHandler<ProgressInitEventArgs> ProgressInit;
26 28
80 m_message = message; 82 m_message = message;
81 OnProgressInit(); 83 OnProgressInit();
82 } 84 }
83 } 85 }
84 86
87 public bool Cancelled {
88 get {
89 lock (m_lock)
90 return m_cancelled;
91 }
92 }
93
94 public bool Cancel() {
95 lock (m_lock) {
96 if (!m_cancelled) {
97 m_cancelled = true;
98 return true;
99 } else {
100 return false;
101 }
102 }
103 }
104
85 protected virtual void OnMessageUpdated() 105 protected virtual void OnMessageUpdated()
86 { 106 {
87 var temp = MessageUpdated; 107 var temp = MessageUpdated;
88 if (temp != null) 108 if (temp != null)
89 { 109 {