ms was declared in the class as
MemoryStream ms;
ReadFromStream was a placeholder for the example. Note that the second version of the code works, and the first doesn't so it's kind of irrelevant what the function actually does, as it's the same function. It is in fact calling a member of another class
declared thus:
That implementation does this:
public async Task<bool> ReadFromStream(IInputStream iis)
{
byte [] retb = new byte[len];
int read = await s.ReadAsync(retb, len, CancellationToken.None);
foreach (byte b in retb)
{
if (b !=0) return true;
}
return false;
}
This reads a buffer full of zeroes, and always returns false. ReadAsync is my extension method that is implmemented thus (like my other question hints at here:
https://social.msdn.microsoft.com/Forums/windowsapps/en-US/c32f6a9a-da50-4212-8ef0-a12530755492/when-does-iinputstreamreadasync-return-a-different-buffer?forum=winappswithcsharp )
public static async Task<int> ReadAsync(this IInputStream s, byte[] b, uint len, CancellationToken ct,
InputStreamOptions opt=InputStreamOptions.None, bool bThrowIfShort = true)
{
var buf = b.AsBuffer();
IBuffer bRet = await s.ReadAsync(buf, len, opt).AsTask(ct);
int read = (int) bRet.Length;
if (bThrowIfShort && (len != read))
{
throw new EndOfStreamException(string.Format("Short stream: {0} != {1}", len, read));
}
if (bRet != buf)
{
bRet.CopyTo(0, b, 0, read);
}
return read;
}
Anthony Wieser | Wieser Software Ltd |
www.wieser-software.com