问题描述
privatevoidWaitForConnectionCallBack(IAsyncResultiar){try{//GetthepipeNamedPipeServerStreampipeServer=(NamedPipeServerStream)iar.AsyncState;//EndwaitingfortheconnectionpipeServer.EndWaitForConnection(iar);byte[]buffer=newbyte[255];//ReadtheincomingmessagepipeServer.Read(buffer,0,255);//ConvertbytebuffertostringstringstringData=Encoding.UTF8.GetString(buffer,0,buffer.Length);Debug.WriteLine(stringData+Environment.NewLine);//PassmessagebacktocallingformPipeMessage.Invoke(stringData);//KilloriginalseverandcreatenewwaitserverpipeServer.Close();pipeServer=null;pipeServer=newNamedPipeServerStream(_pipeName,PipeDirection.In,1,PipeTransmissionMode.Byte,PipeOptions.Asynchronous);//Recursivelywaitfortheconnectionagainandagain....pipeServer.BeginWaitForConnection(newAsyncCallback(WaitForConnectionCallBack),pipeServer);}catch{return;}下面的代码是什么意思,为什么要杀死,再新建呢?我有程序(想参考这个代码)要连续运行,一秒接收3次数据,要运行一个小时,或更长。会不会有性能的问题?源码链接http://www.codeproject.com/Tips/492231/Csharp-Async-Named-Pipes//KilloriginalseverandcreatenewwaitserverpipeServer.Close();pipeServer=null;pipeServer=newNamedPipeServerStream(_pipeName,PipeDirection.In,1,PipeTransmissionMode.Byte,PipeOptions.Asynchronous);//Recursivelywaitfortheconnectionagainandagain....pipeServer.BeginWaitForConnection(newAsyncCallback(WaitForConnectionCallBack),pipeServer);
解决方案
解决方案二:
没有人回呢,自己顶!
解决方案三:
没有人回呢,自己顶!