using System.Windows.Forms; using System; namespace Implab.Fx { public class ControlBoundPromise : Promise { readonly Control m_target; public ControlBoundPromise(Control target) { Safe.ArgumentNotNull(target, "target"); m_target = target; } protected override void SignalSuccess(Promise.HandlerDescriptor handler) { if (m_target.InvokeRequired) m_target.BeginInvoke(new Action.HandlerDescriptor>(base.SignalSuccess), handler); else base.SignalSuccess(handler); } protected override void SignalCancelled(Promise.HandlerDescriptor handler, Exception reason) { if (m_target.InvokeRequired) m_target.BeginInvoke(new Action.HandlerDescriptor,Exception>(base.SignalCancelled), handler, reason); else base.SignalCancelled(handler, reason); } protected override void SignalError(Promise.HandlerDescriptor handler, Exception error) { if (m_target.InvokeRequired) m_target.BeginInvoke(new Action.HandlerDescriptor,Exception>(base.SignalError), handler, error); else base.SignalError(handler, error); } } }