private void SendCommandAsyncPrivate(RawLineId id, string command, StringParameter messageParameter = null, Stream rawData = null, Action<ParsedLineEventArgs> onAnswer = null, bool disposeStream = false, long bytesToSend = -1) { var eventArgs = new ParsedLineEventArgs(id, command, messageParameter, rawData); if (onAnswer != null) { List<Action<ParsedLineEventArgs>> delList; if (!this.onAnswerDelegates.TryGetValue(id, out delList)) { delList = new List<Action<ParsedLineEventArgs>>(); this.onAnswerDelegates.Add(id, delList); } delList.Add(onAnswer); } command = EscapeString(command); var parameterString = EscapeString(messageParameter == null ? "" : messageParameter.Parameter); if (rawData != null && bytesToSend == -1) { bytesToSend = rawData.Length - rawData.Position; } string rawDataString = rawData == null ? string.Empty : string.Format(" RAWDATA {0}", bytesToSend); string commandLine = string.Format("{0} {1}{2}", command, parameterString, rawDataString); Logger.WriteLine("Sending: {0}, with {1}", TraceEventType.Information, commandLine, id); byte[] commandBytes = this.encoding.GetBytes(commandLine + "\0"); byte[] idBytes = id.GetIdBytes(); var completeCommandBytes = new byte[commandBytes.Length + idBytes.Length + 1]; Array.Copy(idBytes, 0, completeCommandBytes, 0, idBytes.Length); completeCommandBytes[idBytes.Length] = 0x20; // Code for Space Array.Copy(commandBytes, 0, completeCommandBytes, idBytes.Length + 1, commandBytes.Length); this.EnqueuePacket( new SendPacket(completeCommandBytes, eventArgs, rawData, this, disposeStream, bytesToSend)); lock (this.sendSync) { if (this.currentPacket == null) { this.SendNextPacket(); } } }