diff Implab.Fx/ControlBoundPromise.cs @ 72:d67b95eddaf4 v2

promises refactoring
author cin
date Thu, 04 Sep 2014 18:47:12 +0400
parents
children b4c4d65b7def
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Implab.Fx/ControlBoundPromise.cs	Thu Sep 04 18:47:12 2014 +0400
@@ -0,0 +1,30 @@
+using System.Windows.Forms;
+using System;
+
+
+namespace Implab.Fx {
+    public class ControlBoundPromise<T> : Promise<T> {
+        readonly Control m_target;
+
+        public ControlBoundPromise(Control target) {
+            Safe.ArgumentNotNull(target, "target");
+
+            m_target = target;
+        }
+
+        public ControlBoundPromise(Control target, IPromise parent, bool cancellable)
+            : base(parent, cancellable) {
+            Safe.ArgumentNotNull(target, "target");
+
+            m_target = target;
+        }
+
+        protected override void InvokeHandler(HandlerDescriptor handler) {
+            if (m_target.InvokeRequired)
+                m_target.BeginInvoke(new Action<HandlerDescriptor>(base.InvokeHandler), handler);
+            else
+                base.InvokeHandler(handler);
+        }
+    }
+}
+