private static void ApplyData(IAsyncResult inResult) { MnDataBroker theReader = inResult.AsyncState as MnDataBroker; int sizeReadData; try { sizeReadData = theReader.PipeServer.EndRead(inResult); if (sizeReadData == 0) { theReader.PipeServer.Disconnect(); } } catch (Exception theException) { theReader.PipeServer.Disconnect(); System.Diagnostics.Debug.WriteLine(theException); return; } if (sizeReadData > 0) { lock (theReader.Queue) { for (int i = 0; i < sizeReadData; i++) { theReader.Queue.Enqueue(theReader._buffer[i]); } } theReader.HasData.Set(); theReader.ReadPipeData(); } }
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); } }