public async System.Threading.Tasks.Task<List<string[]>> GetNewData() { var data = await Task<List<string[]>>.Run(() => { StreamString reader = new StreamString(PipeClient); List<string[]> inputData = new List<string[]>(); var s = reader.ReadString(); if (s.Equals("end")) return null; while (!s.Equals("send")) { string[] parsedData = s.Split(',').ToArray(); string[] resultArray = new string[parsedData.Length]; resultArray[parsedData.Length - 1] = parsedData[parsedData.Length - 1]; decimal value; for (int i = 0; i < parsedData.Length - 1; i++) { if (Decimal.TryParse(parsedData[i], out value)) resultArray[i] = value.ToString(); else resultArray[i] = ""; } inputData.Add(resultArray); s = reader.ReadString(); } return inputData; }); Task.WaitAll(); return data; }
static void Main(string[] args) { NamedPipeServerStream pipeServer = new NamedPipeServerStream("PipeConnection", PipeDirection.InOut, 4, PipeTransmissionMode.Message, PipeOptions.Asynchronous); pipeServer.WaitForConnection(); Console.WriteLine("Connected"); Console.WriteLine("Enter data in format - %d,%d,%d ... (\"send\" to send data, \"end\" to stop input)"); StreamString ss = new StreamString(pipeServer); string input = Console.ReadLine(); while (!input.Equals("end")) { while (!input.Equals("send")) { ss.WriteString(input + ',' + DateTime.Now.ToString()); input = Console.ReadLine(); //Thread.Sleep(1000); } Console.WriteLine("Data sent"); ss.WriteString("send"); input = Console.ReadLine(); } ss.WriteString("end"); pipeServer.Close(); }