本文整理匯總了C#中System.IO.Pipes.NamedPipeServerStream.EndWrite方法的典型用法代碼示例。如果您正苦於以下問題:C# NamedPipeServerStream.EndWrite方法的具體用法?C# NamedPipeServerStream.EndWrite怎麽用?C# NamedPipeServerStream.EndWrite使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.Pipes.NamedPipeServerStream
的用法示例。
在下文中一共展示了NamedPipeServerStream.EndWrite方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: PipeServerAsyncEnumerator
private static IEnumerator<Int32> PipeServerAsyncEnumerator(AsyncEnumerator ae) {
// Each server object performs asynchronous operation on this pipe
using (var pipe = new NamedPipeServerStream(
"Echo", PipeDirection.InOut, -1, PipeTransmissionMode.Message,
PipeOptions.Asynchronous | PipeOptions.WriteThrough)) {
// Asynchronously accept a client connection
pipe.BeginWaitForConnection(ae.End(), null);
yield return 1;
// A client connected, let's accept another client
var aeNewClient = new AsyncEnumerator();
aeNewClient.BeginExecute(PipeServerAsyncEnumerator(aeNewClient),
aeNewClient.EndExecute);
// Accept the client connection
pipe.EndWaitForConnection(ae.DequeueAsyncResult());
// Asynchronously read a request from the client
Byte[] data = new Byte[1000];
pipe.BeginRead(data, 0, data.Length, ae.End(), null);
yield return 1;
// The client sent us a request, process it
Int32 bytesRead = pipe.EndRead(ae.DequeueAsyncResult());
// Just change to upper case
data = Encoding.UTF8.GetBytes(
Encoding.UTF8.GetString(data, 0, bytesRead).ToUpper().ToCharArray());
// Asynchronously send the response back to the client
pipe.BeginWrite(data, 0, data.Length, ae.End(), null);
yield return 1;
// The response was sent to the client, close our side of the connection
pipe.EndWrite(ae.DequeueAsyncResult());
} // Close happens in a finally block now!
}
示例2: BeginWriteCallback
private void BeginWriteCallback(IAsyncResult iar)
{
pipeServer = (NamedPipeServerStream)iar.AsyncState;
pipeServer.EndWrite(iar);
sendRequested = false;
pipeServer.Flush();
}