private void Receive() { try { StateObject state = new StateObject(); state.WorkSocket = MySocket; MySocket.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
private void BeginReceive() { Console.WriteLine("{0} BeginReceive", DateTime.Now.ToString("HH:mm:ss.fff")); lock (LockObject) { if (IsClosed) { throw new IOException("ネットワークが切断しています。"); } IsReceiving = true; //受信バッファ byte[] buffer = new byte[1024]; //非同期データ受信開始 MySocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveDataCallback), buffer); } }