private void BeginReadCallbackProcessing(IAsyncResult ar) { #if !SILVERLIGHT if (log.IsDebugEnabled) log.Debug(__Res.GetString(__Res.Rtmp_SocketBeginRead, _connectionId)); #endif byte[] buffer = ar.AsyncState as byte[]; if (!IsClosed) { try { _lastAction = DateTime.Now; int readBytes = _rtmpNetworkStream.EndRead(ar); _readBytes += readBytes; if (readBytes > 0) { _readBuffer.Append(buffer, 0, readBytes); //Leave IOCP thread #if !SILVERLIGHT ThreadPoolEx.Global.QueueUserWorkItem(OnReceivedCallback, null); #else ThreadPool.QueueUserWorkItem(new WaitCallback(OnReceivedCallback), null); #endif } else // No data to read Close(); } catch (Exception ex) { HandleError(ex); } finally { SocketBufferPool.Pool.CheckIn(buffer); } } else { SocketBufferPool.Pool.CheckIn(buffer); } }