Old post I know, but thought I'd post my C++/CX method here in case it helps someone googling. I was attempting to shoehorn the asyncness of it all into an existing synchronous library. My solution was a 2 step method:
1. Call LoadAsync(1), having set the input stream options to Partial. keep the task it throws back. In subsequent calls, before calling LoadAsync, check that the previous task .isdone() comes back and only call (and keep the result) if it has finished. This avoids the runtime throwing a fit from you calling LoadAsync with a load already in progress.
2. Read upto the number of bytes reported in DataReader->UnconsumedBufferLength.
Simples. You never block on the potentially blocking call to LoadAsync, and you consume as much data as is currently available.
No comments:
Post a Comment