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


C# StreamReader.ReadToEndAsync方法代码示例

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


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

示例1: GetResult

        private static async Task<UrlResult> GetResult(string url)
        {
            var startTime = DateTime.Now;

            try
            {
                var sw = new Stopwatch();
                sw.Start();
                var webRequest = (HttpWebRequest)WebRequest.Create(url);
                webRequest.Headers[HttpRequestHeader.AcceptEncoding] = "gzip,deflate,sdch";

                using (var response = (HttpWebResponse)await webRequest.GetResponseAsync())
                using (var stream = response.GetResponseStream())
                using (var sr = new StreamReader(stream))
                {
                    var result = await sr.ReadToEndAsync();
                    if (response.StatusCode == HttpStatusCode.OK)
                        return new UrlResult((int)sw.ElapsedMilliseconds, result.Length, startTime, url, Thread.CurrentThread.ManagedThreadId);
                    
                    return new UrlResult(startTime, url);
                }
            }
            catch (Exception ex)
            {
                return new UrlResult(startTime, url);
            }
        }
开发者ID:nordineb,项目名称:Netling,代码行数:27,代码来源:UrlJobExtensions.cs

示例2: HandleFileAsync

 static async Task<int> HandleFileAsync(string file)
 {
     int count = 0;
     // ... Use async StreamReader method.
     using (StreamReader reader = new StreamReader(file))
     {
         string v = await reader.ReadToEndAsync();
         count += v.Length;
         for (int i = 0; i < 10000; i++)
         {
             int x = v.GetHashCode();
             if (x == 0)
             {
                 count--;
             }
         }
     }
     Console.WriteLine("HandleFile exit");
     return count;
 }
开发者ID:darshanmp,项目名称:Remote-NoSQL-DB,代码行数:20,代码来源:EventLg.cs

示例3: GetBodies

        public async Task<List<Body>> GetBodies(IByteStreamReader streamReader, ContentTypeFieldValue contentType, string transportEncoding)
        {
            var reader = new BufferedByteReader(streamReader);
           
            switch (contentType.Type)
            {
                case "multipart":
                    var bodyPartReader = new BodyReader(ContentType, Header.ContentTransferEncoding);

                    var bodies = await bodyPartReader.ReadBody(reader);
                    break;
                case "text":
                    var textString = "";
                    using (var memstream = await streamReader.GetMemoryStreamAsync())
                    {
                        using (var unEncoded = await MailMethods.UnEncode(memstream, Header.ContentTransferEncoding))
                        {
                            using (var textReader = new StreamReader(unEncoded, Encoding.GetEncoding(Header.ContentType.Charset)))
                            {
                                textString = await textReader.ReadToEndAsync();
                            }
                        }
                    }
                    var textBody = new Body();
                    textBody.Content = (new MemoryStream(Encoding.Unicode.GetBytes(textString)));
                    break;
                case "image":
                case "audio":
                case "video":
                case "application":
                    var binaryBody = new Body();
                    binaryBody.Content = await streamReader.GetMemoryStreamAsync());
                    break;
            }
        }
开发者ID:KeesPolling,项目名称:Popmail,代码行数:35,代码来源:BodyPartReader.cs


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