2012年6月20日星期三

Operation Task class

Operation Task class

  Operation Task class 用于处理一个operation,处理完后通知外部。

namespace Demo {	public abstract class OperationTaskBase {		private Boolean _isTaskCompleted;				public Boolean IsTaskCompleted {			get {				return this._isTaskCompleted;			}			set {				this._isTaskCompleted = value;				if (this._isTaskCompleted) {					this.OnTaskCompleted();				}			}		}			public event EventHandler TaskCompleted;		protected virtual void OnTaskCompleted() {			if (this.TaskCompleted != null) {				this.TaskCompleted(this, EventArgs.Empty);			}		}					public abstract void Execute();	}	public class OperationTask<T> : OperationTaskBase {		private Action<T> _action;		private T _parameter;		public OperationTask() {		}		public Action<T> Action {			get {				return this._action;			}			set {				this._action = value;			}		}		public T Parameter {			get {				return this._parameter;			}			set {				this._parameter = value;			}		}		public override void Execute() {			if (this.Action != null) {				this.Action.Invoke(this._parameter);			}		}	}	public class OperationTask : OperationTaskBase {		private Action _action;		public OperationTask() {		}		public Action Action {			get {				return this._action;			}			set {				this._action = value;			}		}		public override void Execute() {			if (this.Action != null) {								this.Action.Invoke();			}		}	}}                

  


TAG: