public AsyncOperation asyncOp;        public Form1()
        {
            InitializeComponent();
            this.asyncOp = AsyncOperationManager.CreateOperation(this);
        }    
    private  void ResultMessage(object sender,NumberEventArgs args)
        {         //1
             this.Invoke(new Action(()=>
            {
                this.textBox1.Text = args.Number.ToString();
            }));
//2
             this.Invoke((MethodInvoker)delegate
             {
                 this.textBox1.Text = args.Number.ToString();
             });
//3
             this.AsyncDispatchToContext(() =>
                 this.textBox1.Text = args.Number.ToString());//4
             this.SyncDispatchToContext(() =>
                 this.textBox1.Text = args.Number.ToString());       
        }        protected void AsyncDispatchToContext(Action operation)
        {
            this.asyncOp.Post((obj) => operation(), null);
        }        protected void SyncDispatchToContext(Action operation)
        {
            this.asyncOp.SynchronizationContext.Send((obj) => operation(), null);
        }不明白1,2,3,4 的区别是什么 
都在什么情况下使用
执行一般关闭窗口 目前3是没问题的

解决方案 »

  1.   

    MethodInvoker表示一个委托,该委托可执行托管代码中声明为 void 且不接受任何参数的任何方法。
     public delegate void MethodInvoker();
        //     封装一个方法,该方法不具有参数并且不返回值。
        [TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089")]
    public delegate void Action();Invoke 要求一个delegate 变量,而上面两个都是delegate 变量