日期:2014-05-17  浏览次数:21119 次

C# delegate 带参数
C# code


        //windows ce 的winform 不能使用异步委托
        private void linkLabel_Click(object sender, EventArgs e)
        {
               Thread t = new Thread(new ThreadStart(DoWork));
               t.IsBackground = true;
               t.Start();  
        }

        private delegate void MyDelegate();
     
        string ss="";

        private void DoWork()
        {
            //....... 

            ss ="abcd";

            if (this.label6.InvokeRequired)
            {
                Invoke(new MyDelegate(MyMethod));
            }
        }

        private void MyMethod()
        {
           label6.Text = ss;
        }

        



现在我想改成  

  private void MyMethod(string str)

  private delegate void MyDelegate(string str);

这个 string str 怎样在里面传递?

 

------解决方案--------------------
http://technet.microsoft.com/zh-cn/magazine/system.threading.parameterizedthreadstart%28VS.95%29.aspx
------解决方案--------------------
Invoke(new MyDelegate(MyMethod), new object[] { ss });
------解决方案--------------------
BeginInvoke(委托,参数),多个参数可以用数组表示