日期:2014-05-18 浏览次数:21258 次
public delegate void appendText(string[] text);
public void Read_Callback(IAsyncResult ar)
        {
                                         socket.BeginReceiveFrom(state.buffer, 0, StateObject.BUFFER_SIZE, SocketFlags.None, ref endPoint, Read_Callback, state);
                              AppendText(text);
                          }
            else
            {
                socket.Close();
            }
        }
 
void AppendText(string[] text)
        {
            if (this.lvwLogOutput.InvokeRequired)//ListView控件
            {
                try
                {
                    appendText appendtext = new appendText(AppendText);//委托
                    this.Invoke(appendtext, new object[] { text });//有时候这里就会出现异常。NullReferenceException 
                   
                }
                catch (NullReferenceException nullREP)
                {
                                   }
            }
            else
            {
                lvwLogOutput.Items.Add(new ListViewItem(new string[] { text[0], text[1], text[2], text[4] }, -1));
                lvwLogOutput.TopItem = lvwLogOutput.Items[lvwLogOutput.Items.Count - 1];
                         }
        }