典型的跨线程访问界面控件的问题,需要用到委托
....
delegate void SetTextCallback(string text);...
                    //this.listBoxState.Items.Add("与服务器断开连接!");
                    this.SetText("与服务器断开连接!");
                    break;
...
private void SetText(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.listBoxState.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.listBoxState.Items.Add(text);
}
}