/// <summary> /// On data recieved event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnDataRecieved(object sender, DataRecievedEventArgs e) { if (InvokeRequired) { Invoke(new DataRecievedDelegate(this.OnDataRecieved), new object[] { sender, e }); return; } string dataIn = e.data; // if we detect a line terminator int index; while (dataIn.Length > 0 && ((index = dataIn.IndexOf("\r")) != -1 || (index = dataIn.IndexOf("\n")) != -1)) { string stringIn = dataIn.Substring(0, index); dataIn = dataIn.Remove(0, index + 1); this.AddDataToPartialLine(stringIn); } // if there are bytes left if (dataIn.Length > 0) { this.partialLine = this.AddDataToPartialLine(dataIn); return; } this.PrintLine(this.partialLine); this.partialLine = null; }
private void DataRecieved(string data) { if (this.OnDataRecieved == null) { return; } DataRecievedEventArgs args = new DataRecievedEventArgs(data); this.OnDataRecieved(this, args); }