1 protected void OnReceive(IAsyncResult iar) 2 { 3 IPEndPoint remote = null; 4 byte[] buffer = null; 5 try 6 { 7 UdpClient udpClient = iar.AsyncState as UdpClient; 8 if (udpClient != null) 9 { 10 buffer = udpClient.EndReceive(iar, ref remote); 11 if (buffer.Length > 0) 12 { 13 //处理数据 14 } 15 udpClient.BeginReceive(OnReceive, udpClient); 16 } 17 } 18 catch (ObjectDisposedException ex1) 19 { 20 log.Error("对象资源释放ObjectDisposedException:", ex1); 21 } 22 catch (Exception ex2) 23 { 24 log.Error("接收数据失败:", ex2); 25 26 this.m_Socket.Close(); 27 28 if (this.OnError != null) 29 { 30 this.OnError(this, new ChangedEventArgs(this.m_Name, ex2)); 31 } 32 } 33 }
代码敢不敢用插入代码的方式
知道是什么原因引起的么?