本文整理汇总了C#中NamedPipeServerStream.WriteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream.WriteAsync方法的具体用法?C# NamedPipeServerStream.WriteAsync怎么用?C# NamedPipeServerStream.WriteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamedPipeServerStream
的用法示例。
在下文中一共展示了NamedPipeServerStream.WriteAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PingPong_Async
public async Task PingPong_Async()
{
// Create names for two pipes
string outName = Path.GetRandomFileName();
string inName = Path.GetRandomFileName();
// Create the two named pipes, one for each direction, then create
// another process with which to communicate
using (var outbound = new NamedPipeServerStream(outName, PipeDirection.Out))
using (var inbound = new NamedPipeClientStream(".", inName, PipeDirection.In))
using (RemoteInvoke(PingPong_OtherProcess, outName, inName))
{
// Wait for both pipes to be connected
await Task.WhenAll(outbound.WaitForConnectionAsync(), inbound.ConnectAsync());
// Repeatedly write then read a byte to and from the other process
var data = new byte[1];
for (byte i = 0; i < 10; i++)
{
data[0] = i;
await outbound.WriteAsync(data, 0, data.Length);
data[0] = 0;
int received = await inbound.ReadAsync(data, 0, data.Length);
Assert.Equal(1, received);
Assert.Equal(i, data[0]);
}
}
}