private static void ThreadServerPipe(Object inParam) { MnPipeServer pipeServer = inParam as MnPipeServer; //pipeServer._logs.PutMessage("Start thread"); try { while (true) { IAsyncResult asyncResult = pipeServer._pipeServerStream.BeginWaitForConnection(null, null); asyncResult.AsyncWaitHandle.WaitOne(); pipeServer._pipeServerStream.EndWaitForConnection(asyncResult); MnDataBroker dataBroker = new MnDataBroker(pipeServer._pipeServerStream); while (pipeServer._pipeServerStream.IsConnected || dataBroker.Queue.Count > 0) { try { Int32 marker = dataBroker.ReadInt32(); while (marker != kMarker) { byte sign = dataBroker.ReadByte(); marker = (marker << 8) | sign; } Int32 sizeParams = dataBroker.ReadInt32(); byte[] bufParams = dataBroker.ReadBytes(sizeParams); pipeServer._logs.PutMessage(Encoding.Unicode.GetString(bufParams, 0, sizeParams)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } } } catch (ThreadAbortException e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
private void StartListenPipe(string newPipe) { var pipeServer = new MnPipeServer(_logs, newPipe); _pipeServers.Add(pipeServer); }