private Task <SecsMessage> SendDataMessageAsync(SecsMessage msg, int systembyte) { var token = new TaskCompletionSourceToken(msg, systembyte, MessageType.DataMessage); if (msg.ReplyExpected) { _replyExpectedMsgs[systembyte] = token; } var header = new MessageHeader { S = msg.S, F = msg.F, ReplyExpected = msg.ReplyExpected, DeviceId = DeviceId, SystemBytes = systembyte }; var bufferList = msg.RawDatas.Value; bufferList[1] = new ArraySegment <byte>(header.EncodeTo(new byte[10])); var eap = new SocketAsyncEventArgs { BufferList = bufferList, UserToken = token, }; eap.Completed += _sendDataMessageCompleteHandler; sockClient.Send(eap.BufferList.ToArray(), SocketFlags.None); //if (!sockClient.SendAsync(eap)) // SendDataMessageCompleteHandler(sockClient, eap); return(token.Task); }