日期:2014-05-18 浏览次数:21060 次
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; } }
------解决方案--------------------
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 即可.. //