为BeginGetResponse的MSDN示例代码有两个异步调用,一个获得响应, 和一个从响应缓冲区读取:c#BeginGetResponse:是否有任何理由异步读取字节响应回调?
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.begingetresponse.aspx
看到这一行:
// Begin the Reading of the contents of the HTML page and print it to the console.
IAsyncResult asynchronousInputRead = responseStream.BeginRead(myRequestState.BufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallBack), myRequestState);
我问题是:与同步读取相比,这里有什么优势?
谢谢!
是的,但在这种情况下,BeginRead被从回调中调用;不涉及UI线程。那么为什么不只是做一个同步读取? – Jacko 2011-05-19 12:43:10