当前位置: 首页>>代码示例>>C#>>正文


C# NamedPipeClientStream.WriteAsync方法代码示例

本文整理汇总了C#中System.IO.Pipes.NamedPipeClientStream.WriteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeClientStream.WriteAsync方法的具体用法?C# NamedPipeClientStream.WriteAsync怎么用?C# NamedPipeClientStream.WriteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Pipes.NamedPipeClientStream的用法示例。


在下文中一共展示了NamedPipeClientStream.WriteAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateProfileClientTestWorkerAsync

        private async Task<UserProfileResultMock> CreateProfileClientTestWorkerAsync(string input, CancellationToken ct = default(CancellationToken)) {
            string jsonResp = null;
            using (NamedPipeClientStream client = new NamedPipeClientStream("Microsoft.R.Host.UserProfile.Creator{b101cc2d-156e-472e-8d98-b9d999a93c7a}")) {
                await client.ConnectAsync(ct);
                byte[] data = Encoding.Unicode.GetBytes(input);

                await client.WriteAsync(data, 0, data.Length, ct);
                await client.FlushAsync(ct);

                byte[] responseRaw = new byte[1024];
                var bytesRead = await client.ReadAsync(responseRaw, 0, responseRaw.Length, ct);
                jsonResp = Encoding.Unicode.GetString(responseRaw, 0, bytesRead);
            }
            return Json.DeserializeObject<UserProfileResultMock>(jsonResp);
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:15,代码来源:UserProfileServicePipeTest.cs

示例2: IssueClientRequestAsync

        private static async Task<String> IssueClientRequestAsync(String serverName, String message)
        {
            using (var pipe = new NamedPipeClientStream(serverName, "PipeName", PipeDirection.InOut,
                PipeOptions.Asynchronous | PipeOptions.WriteThrough))
            {
                pipe.Connect(); // Прежде чем задавать ReadMode, необходимо

                pipe.ReadMode = PipeTransmissionMode.Message; // вызвать Connect

                // Асинхронная отправка данных серверу
                Byte[] request = Encoding.UTF8.GetBytes(message);

                await pipe.WriteAsync(request, 0, request.Length);
                // Асинхронное чтение ответа сервера
                Byte[] response = new Byte[1000];

                Int32 bytesRead = await pipe.ReadAsync(response, 0, response.Length);

                return Encoding.UTF8.GetString(response, 0, bytesRead);
            } // Закрытие канала
        }
开发者ID:alex2015,项目名称:ConsoleApplication,代码行数:21,代码来源:MyAsync.cs

示例3: ProfileWorkerAsync

        private async Task<RUserProfileServiceResponse> ProfileWorkerAsync(string name, string log, RUserProfileServiceRequest request, CancellationToken ct) {
            using (NamedPipeClientStream client = new NamedPipeClientStream(name)) {
                try {
                    await client.ConnectAsync(ct);

                    string jsonReq = JsonConvert.SerializeObject(request);
                    byte[] data = Encoding.Unicode.GetBytes(jsonReq.ToString());

                    await client.WriteAsync(data, 0, data.Length, ct);
                    await client.FlushAsync(ct);

                    byte[] responseRaw = new byte[1024];
                    var bytesRead = await client.ReadAsync(responseRaw, 0, responseRaw.Length, ct);
                    string jsonResp = Encoding.Unicode.GetString(responseRaw, 0, bytesRead);
                    return Json.DeserializeObject<RUserProfileServiceResponse>(jsonResp);
                } catch (Exception ex) when (!ex.IsCriticalException()) {
                    _logger.LogError(log, request.Username);
                    return RUserProfileServiceResponse.Blank;
                }
            }
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:21,代码来源:UserProfileManager.cs

示例4: ClientPInvokeChecks

    public static async Task ClientPInvokeChecks()
    {
        using (NamedPipeServerStream server = new NamedPipeServerStream("foo", PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.None, 4096, 4096))
        {
            using (NamedPipeClientStream client = new NamedPipeClientStream(".", "foo", PipeDirection.Out))
            {
                Task serverTask = DoServerOperationsAsync(server);
                client.Connect();

                Assert.False(client.CanRead);
                Assert.False(client.CanSeek);
                Assert.False(client.CanTimeout);
                Assert.True(client.CanWrite);
                Assert.False(client.IsAsync);
                Assert.True(client.IsConnected);
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    Assert.Equal(0, client.OutBufferSize);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Assert.True(client.OutBufferSize > 0);
                }
                else
                {
                    Assert.Throws<PlatformNotSupportedException>(() => client.OutBufferSize);
                }
                Assert.Equal(PipeTransmissionMode.Byte, client.ReadMode);
                Assert.NotNull(client.SafePipeHandle);
                Assert.Equal(PipeTransmissionMode.Byte, client.TransmissionMode);

                client.Write(new byte[] { 123 }, 0, 1);
                await client.WriteAsync(new byte[] { 124 }, 0, 1);
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    client.WaitForPipeDrain();
                }
                else
                {
                    Assert.Throws<PlatformNotSupportedException>(() => client.WaitForPipeDrain());
                }
                client.Flush();

                await serverTask;
            }
        }

        using (NamedPipeServerStream server = new NamedPipeServerStream("foo", PipeDirection.Out))
        {
            using (NamedPipeClientStream client = new NamedPipeClientStream(".", "foo", PipeDirection.In))
            {
                Task serverTask = DoServerOperationsAsync(server);
                client.Connect();

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    Assert.Equal(0, client.InBufferSize);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Assert.True(client.InBufferSize > 0);
                }
                else
                {
                    Assert.Throws<PlatformNotSupportedException>(() => client.InBufferSize);
                }
                byte[] readData = new byte[] { 0, 1 };
                Assert.Equal(1, client.Read(readData, 0, 1));
                Assert.Equal(1, client.ReadAsync(readData, 1, 1).Result);
                Assert.Equal(123, readData[0]);
                Assert.Equal(124, readData[1]);

                await serverTask;
            }
        }
    }
开发者ID:nuskarthik,项目名称:corefx,代码行数:76,代码来源:NamedPipesSimpleTest.cs

示例5: ClientPInvokeChecks

    public static void ClientPInvokeChecks()
    {
        using (NamedPipeServerStream server = new NamedPipeServerStream("foo", PipeDirection.In))
        {
            using (NamedPipeClientStream client = new NamedPipeClientStream(".", "foo", PipeDirection.Out))
            {
                Task serverTask = DoServerOperationsAsync(server);
                client.Connect();
                Console.WriteLine("client.CanRead = {0}", client.CanRead);
                Console.WriteLine("client.CanSeek = {0}", client.CanSeek);
                Console.WriteLine("client.CanTimeout = {0}", client.CanTimeout);
                Console.WriteLine("client.CanWrite = {0}", client.CanWrite);
                Console.WriteLine("client.IsAsync = {0}", client.IsAsync);
                Console.WriteLine("client.IsConnected = {0}", client.IsConnected);
                Console.WriteLine("client.OutBufferSize = {0}", client.OutBufferSize);
                Console.WriteLine("client.ReadMode = {0}", client.ReadMode);
                Console.WriteLine("client.SafePipeHandle = {0}", client.SafePipeHandle);
                Console.WriteLine("client.TransmissionMode = {0}", client.TransmissionMode);

                client.Write(new byte[] { 123 }, 0, 1);
                client.WriteAsync(new byte[] { 124 }, 0, 1).Wait();
                client.WaitForPipeDrain();
                client.Flush();

                serverTask.Wait();
            }
        }

        using (NamedPipeServerStream server = new NamedPipeServerStream("foo", PipeDirection.Out))
        {
            using (NamedPipeClientStream client = new NamedPipeClientStream(".", "foo", PipeDirection.In))
            {
                Task serverTask = DoServerOperationsAsync(server);
                client.Connect();

                Console.WriteLine("client.InBufferSize = {0}", client.InBufferSize);
                byte[] readData = new byte[] { 0, 1 };
                client.Read(readData, 0, 1);
                client.ReadAsync(readData, 1, 1).Wait();
                Assert.Equal(123, readData[0]);
                Assert.Equal(124, readData[1]);

                serverTask.Wait();
            }
        }
    }
开发者ID:gitter-badger,项目名称:corefx,代码行数:46,代码来源:NamedPipesSimpleTest.cs


注:本文中的System.IO.Pipes.NamedPipeClientStream.WriteAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。