本文整理汇总了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);
}
}
示例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;
}
示例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;
}
}