/// <summary> /// 接收消息 /// </summary> public void ReceiverMessage() { LogHelper.WriteMethodLog(true); try { ThreadPool.QueueUserWorkItem(delegate { pipeServer.BeginWaitForConnection((iAsyncResult) => { NamedPipeServerStream server = (NamedPipeServerStream)iAsyncResult.AsyncState; server.EndWaitForConnection(iAsyncResult); StreamReader sr = new StreamReader(server); //StreamWriter sw = new StreamWriter(server); string result = null; string clientName = server.GetImpersonationUserName(); while (true) { result = sr.ReadLine(); if (result == null || result == "End") { continue; } NamedPipeModel mod = JsonHelper.Deserialize <NamedPipeModel>(result); if (this.NamedPipeCallBack != null) { this.NamedPipeCallBack(mod); } } }, pipeServer); }); } catch (Exception ex) { LogHelper.WriteErrorInfoLog("ReceiverMessage", ex); } finally { LogHelper.WriteMethodLog(false); } }
/// <summary> /// 接收消息 /// </summary> public bool SendMessage(NamedPipeModel message) { LogHelper.WriteMethodLog(true); try { StreamWriter sw = new StreamWriter(this.pipeServer); sw.AutoFlush = true; string json = JsonHelper.Serializer <NamedPipeModel>(message); sw.WriteLine(json); return(true); } catch (Exception ex) { LogHelper.WriteErrorInfoLog("ReceiverMessage", ex); return(false); } finally { LogHelper.WriteMethodLog(false); } }
/// <summary> /// 接收消息 /// </summary> public void ReceiverMessage() { LogHelper.WriteMethodLog(true); try { pipeClient.Connect(5000); ThreadPool.QueueUserWorkItem(delegate { StreamReader sr = new StreamReader(pipeClient); string result = null; while (true) { result = sr.ReadLine(); if (result == null || result == "End") { continue; } NamedPipeModel mod = JsonHelper.Deserialize <NamedPipeModel>(result); if (this.NamedPipeCallBack != null) { this.NamedPipeCallBack(mod); } } }); } catch (Exception ex) { LogHelper.WriteErrorInfoLog("ReceiverMessage", ex); } finally { LogHelper.WriteMethodLog(false); } }