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


C# NamedPipeClientStream.FlushAsync方法代码示例

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


在下文中一共展示了NamedPipeClientStream.FlushAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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


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