private static void DispatcherCB(IAsyncResult ares) { SocketAsyncEventArgs args = (SocketAsyncEventArgs)ares.AsyncState; if (Interlocked.Exchange(ref args.in_progress, 0) != 1) { throw new InvalidOperationException("No operation in progress"); } SocketAsyncOperation op = args.LastOperation; // Notes; // -SocketOperation.AcceptReceive not used in SocketAsyncEventArgs // -SendPackets and ReceiveMessageFrom are not implemented yet if (op == SocketAsyncOperation.Receive) { args.ReceiveCallback(ares); } else if (op == SocketAsyncOperation.Send) { args.SendCallback(ares); } #if !SSHARP else if (op == SocketAsyncOperation.ReceiveFrom) { args.ReceiveFromCallback(ares); } else if (op == SocketAsyncOperation.SendTo) { args.SendToCallback(ares); } #endif else if (op == SocketAsyncOperation.Accept) { args.AcceptCallback(ares); } #if !NETCF else if (op == SocketAsyncOperation.Disconnect) { args.DisconnectCallback(ares); } #endif else if (op == SocketAsyncOperation.Connect) { args.ConnectCallback(ares); } /* * else if (op == Socket.SocketOperation.ReceiveMessageFrom) * else if (op == Socket.SocketOperation.SendPackets) */ else { throw new NotImplementedException(String.Format("Operation {0} is not implemented", op)); } }