private void ReadHeader(NetworkStream stream) { lock (stream) { TcpClient2InputStreamContext ctx = new TcpClient2InputStreamContext(); ctx.ClientStream = stream; ctx.Header = new byte[sizeof(long) + sizeof(int)]; ctx.HeaderRead = false; stream.BeginRead(ctx.Header, 0, ctx.Header.Length, BeginReadCallback, ctx); } }
private void ReadHeader(NetworkStream stream) { contextCount++; TcpClient2InputStreamContext ctx = new TcpClient2InputStreamContext(); ctx.ID = contextCount; ctx.ClientStream = stream; ctx.Header = new byte[sizeof(long)]; ctx.HeaderRead = false; stream.BeginRead(ctx.Header, 0, ctx.Header.Length, BeginReadCallback, ctx); }
private void ReadHeader(NetworkStream stream) { contextCount++; TcpClient2InputStreamContext ctx = new TcpClient2InputStreamContext(); ctx.ID = contextCount; ctx.ClientStream = stream; ctx.Header = new byte[sizeof(long)]; ctx.HeaderRead = false; Task<int>.Factory.FromAsync<byte[], int, int>(stream.BeginRead, stream.EndRead, ctx.Header, 0, ctx.Header.Length, ctx).ContinueWith(BeginReadCallback).ContinueWith(TaskExceptionHandler, TaskContinuationOptions.OnlyOnFaulted); ; }