Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            TaskPromise task = EventBus.Bus.PublishEvent(null, this, new
            {
                controler = "UserLogin",
                action    = "Login",
                userName  = this.txt_name.Text,
                password  = this.txt_password.Text
            });

            task.SetComplete(this, (a) =>
            {
                this.Cursor = Cursors.Default;

                this.IsLogin = a.TakeResult <bool>();
                if (this.IsLogin)
                {
                    this.Close();
                }
                else
                {
                    MessageBox.Show(this, "登录失败!", "提示:");
                }
            });
        }
Пример #2
0
        //为当前control设置TaskPromise
        private void SetTaskPromiseToControl(object control, TaskPromise promise)
        {
            Type ctl = control.GetType();
            var  pro = ctl.GetProperty("Promise", BindingFlags.NonPublic | BindingFlags.Instance);

            if (pro != null)
            {
                pro.SetValue(control, promise);
            }
        }
Пример #3
0
        public static void SetComplete(this TaskPromise promise, Control control, Action <TaskPromise> callback)
        {
            if (promise == null)
            {
                throw new NullReferenceException();
            }


            if (control == null)
            {
                promise.SetCompleteInvoke(callback);
                return;
            }

            promise.SetCompleteInvoke(p => {
                control.InvokeAsync(callback, p);
            });
        }