试图理解流和async/await
.如果我正确地await
将执行返回给调用者,那么我希望下面代码的结果是:
before calling async ReadToEnd
after the call to ReadToEnd
before calling async ReadToEnd
after the call to ReadToEnd
Run Code Online (Sandbox Code Playgroud)
但它是这样的
before calling async ReadToEnd
after the call to ReadToEnd
before calling async ReadToEnd
after await in ReadToEnd. streamReader.BaseStream.GetType(): System.IO.MemoryStream
after the call to ReadToEnd
Run Code Online (Sandbox Code Playgroud)
似乎在调用时使用StreamReader
带有FileStream
下面的a 确实返回到调用者 StreamReader.ReadToEndAsync()
,但是当使用StreamReader
带有MemoryStream
下面的时它不起作用.
试图了解发生了什么事我读过的.NET源代码,来到在调用conculssion StreamReader.ReadToEndAsync()
与MemoryStream
下最终调用ReadAsync()
(来源上BaseStream).在的情况下MemoryStream
的ReadAsync()
仅仅是不是一个真正的asynhnornous方法,因此不会返回给调用者.
我的理解是否正确?
using System;
using System.Text;
using System.Linq; …
Run Code Online (Sandbox Code Playgroud)