110,568
社区成员
发帖
与我相关
我的任务
分享
private delegate void Handler(); //可带参数..
private void Accessor() //注意: 参数列表, 要与 Handler 对应..
{
if (this.InvokeRequired)
{
this.Invoke(new Handler(this.Accessor)); //如有参数, 在此传入..
}
else
{
lock (this)
{
//TODO: 在这里访问或处理..
}
}
}
private void Run()
{
Thread thread = new Thread(new ThreadStart(this.Accessor));
thread.Name = "访问控件";
thread.IsBackground = true;
thread.Start();
}
//
// 说明: 调用 Run 即可..
//
delegate void DisplayStringDelegate(string str);
private void AppendString(string str)
{
if(this.Label1.InvokeRequird)
{
DisplayStringDelegate dd=new DisplayStringDelegate(AppendString);
this.Label1.Invoked(dd "abcdefg");
}
else
{
this.Label.Text+=str;
}
}