我在WinRT / Metro应用程序中使用StreamSocket.InputStream.ReadAsync()进行字节读取,并且需要知道实际读取了多少字节。此读取被视为同步读取,必须保持同步读取。
以下是相关的代码段:
var receivedTask = this._socket.InputStream.ReadAsync(buffer.AsBuffer(), length, Windows.Storage.Streams.InputStreamOptions.None);
receivedTask.AsTask().Start();
receivedTask.AsTask().Wait(timeout);
// Need code here to get the number of bytes received
if (receivedBytes > 0)
{
receivedTotal += receivedBytes;
continue;
}
else
{
// Socket Closed
}