view Implab.Fx/ControlBoundPromise.cs @ 145:706fccb85524 v2

RC: cancellation support for promises + tests
author cin
date Sun, 08 Mar 2015 02:52:27 +0300
parents f75cfa58e3d4
children 97fbbf816844
line wrap: on
line source

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;
        }

        protected override void SignalSuccess(Promise<T>.HandlerDescriptor handler) {
            if (m_target.InvokeRequired)
                m_target.BeginInvoke(new Action<Promise<T>.HandlerDescriptor>(base.SignalSuccess), handler);
            else
                base.SignalSuccess(handler);
        }

        protected override void SignalCancelled(Promise<T>.HandlerDescriptor handler, Exception reason) {
            if (m_target.InvokeRequired)
                m_target.BeginInvoke(new Action<Promise<T>.HandlerDescriptor,Exception>(base.SignalCancelled), handler, reason);
            else
                base.SignalCancelled(handler, reason);
        }

        protected override void SignalError(Promise<T>.HandlerDescriptor handler, Exception error) {
            if (m_target.InvokeRequired)
                m_target.BeginInvoke(new Action<Promise<T>.HandlerDescriptor,Exception>(base.SignalError), handler, error);
            else
                base.SignalError(handler, error);
        }

    }
}