System.IO.Pipes.NamedPipeServerStream.WaitForConnectionAsync C# (CSharp) Method

WaitForConnectionAsync() public method

public WaitForConnectionAsync ( ) : System.Threading.Tasks.Task
return System.Threading.Tasks.Task
        public System.Threading.Tasks.Task WaitForConnectionAsync() { throw null; }
        public System.Threading.Tasks.Task WaitForConnectionAsync(System.Threading.CancellationToken cancellationToken) { throw null; }

Same methods

NamedPipeServerStream::WaitForConnectionAsync ( System cancellationToken ) : System.Threading.Tasks.Task
NamedPipeServerStream::WaitForConnectionAsync ( ) : Task
NamedPipeServerStream::WaitForConnectionAsync ( CancellationToken cancellationToken ) : Task

Usage Example

示例#1
0
        public async Task NamedPipeWriteViaAsyncFileStream(bool asyncWrites)
        {
            string name = Guid.NewGuid().ToString("N");
            using (var server = new NamedPipeServerStream(name, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
            {
                Task serverTask = Task.Run(async () =>
                {
                    await server.WaitForConnectionAsync();
                    for (int i = 0; i < 6; i++)
                        Assert.Equal(i, server.ReadByte());
                });

                WaitNamedPipeW(@"\\.\pipe\" + name, -1);
                using (SafeFileHandle clientHandle = CreateFileW(@"\\.\pipe\" + name, GENERIC_WRITE, FileShare.None, IntPtr.Zero, FileMode.Open, (int)PipeOptions.Asynchronous, IntPtr.Zero))
                using (var client = new FileStream(clientHandle, FileAccess.Write, bufferSize: 3, isAsync: true))
                {
                    var data = new[] { new byte[] { 0, 1 }, new byte[] { 2, 3 }, new byte[] { 4, 5 } };
                    foreach (byte[] arr in data)
                    {
                        if (asyncWrites)
                            await client.WriteAsync(arr, 0, arr.Length);
                        else
                            client.Write(arr, 0, arr.Length);
                    }
                }

                await serverTask;
            }
        }
All Usage Examples Of System.IO.Pipes.NamedPipeServerStream::WaitForConnectionAsync