解决从不是创建控件的线程访问的问题

三木哥 2006-06-20 03:20:33
我在对Label1.Text = "aaa"进行操作时提示"从不是创建控件Label1的线程访问的异常.
然后我写了一个方法:
SetLabelText()
{
Label1.Text = "aaa";
}
然后用this.Invoke(new MethodInvoker(SetLabelText));处理.
假如我将SetLabelText方法改成:
SetLabelText(string text)
{
Label1.Text = text;
}
用this.Invoke(new MethodInvoker(SetLabelText));作调用时该如何传参数?
...全文
141 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
o光o 2006-10-08
  • 打赏
  • 举报
回复
MethodInvoker 是简单委托不带参数

private delegate void MethodInvoker2(string message);//定义委托,放在方法外面


MethodInvoker2 me=SetLabelText;
this.BeginInvoke( mi, "aaa");
三木哥 2006-06-21
  • 打赏
  • 举报
回复
lastup
三木哥 2006-06-20
  • 打赏
  • 举报
回复
up
三木哥 2006-06-20
  • 打赏
  • 举报
回复
public void SetLabelText( string text)
{
Label1.Text = text;
}
MethodInvoker mi = new MethodInvoker( this.SetLabelText);
this.BeginInvoke( mi, new object[]{ myText} );
怎么提示SetLabelText的重载与委托MethodInvoker不匹配.
wpater 2006-06-20
  • 打赏
  • 举报
回复
http://msdn2.microsoft.com/zh-cn/library/ms171728.aspx
wpater 2006-06-20
  • 打赏
  • 举报
回复
http://blog.csdn.net/knight94/archive/2006/03/16/626584.aspx

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧