C# delegate 带参数,该怎么解决
C# delegate 带参数C# code//windows ce 的winform 不能使用异步委托private void linkLabel_Click(object
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(委托,参数),多个参数可以用数组表示