0

My sample application gets a COM IStream instance from a IPortableDeviceResources::GetStream() function. I want to read the device object contents asynchronously using this IStream object. How can I do that using an asynchronous moniker?

1 Answers1

1

IStream is synchronous by design. I would first ask what your scenario is for needing this to be asynchronous.

For example, if the reason for wanting an asynchronous data stream is so that you won't block the UI thread, you can perform the IStream operations in a worker thread.

If the reason is so that you can issue multiple parallel reads, MTP 1.0 devices don't support this because at the driver level, the requests will still be processed sequentially in a single, global, MTP session. MTP 2.0 supports multi-session which allows for multiple parallel connections to the same device, but so far not many devices have adopted this. Most, if not all, MTP devices in the market are MTP 1.0.

Lisa O
  • 125
  • 2
  • Thanks for providing these details. I am currently reading data from the IStream object on the worker thread. I am concerned that the worker thread will be monopolized while reading a large file on a slow device. If I can use asynchronous monikers to read the IStream data then I can abort the read when required and also let other tasks to run while the OS is dispatching the read to the underlying MTP device. But I am not sure if I can use asynchronous monikers here? – user2059733 Feb 19 '13 at 19:05
  • MTP transfers via the Windows WPD API are done in blocks, you read from the device IStream, write to your memory/file, then loop. After every read check a synchronized flag before looping. – Jason Harrison Nov 01 '15 at 14:19