I have a NetworkStream that I read asynchronously (using async / wait)
await Task<int>.Factory.FromAsync((cb, state) => stream.BeginRead(buffer, offset, readLen - offset), stream.EndRead, null);
Unfortunately, an io exception sometimes occurs: "The I / O operation was interrupted due to a stream or application request."
I believe that I applied the requirement registered in Socke.EndReceive: http://msdn.microsoft.com/en-us/library/w7wtt64b.aspx . What are the conditions:
All I / O initiated by this stream is canceled when this stream exits. The expected asynchronous operation may fail if the thread completes before the operation completes.
Since the async method works in the scheduler by default, this requirement cannot be guaranteed.
Is there any way around this? Do I need to run a dedicated thread to initialize I / O?
Regards, Dirk
source share