Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is really tricky, because <code>XmlReader</code> doesn't provide any asynchronous interface.</p> <p>I'm not really sure how much asynchronously does the <code>BeginRead</code> behave when you ask it to read 0 bytes - it might as well invoke the callback immediately and then block when you call <code>Read</code>. This could be the same thing as calling <code>Read</code> directly and then scheduling the next <code>Read</code> in a thread pool for example using <code>QueueWorkItem</code>.</p> <p>It may be better to use <code>BeginRead</code> on the network stream to read data for example in 10kB chunks (while the system waits for the data, you wouldn't be blocking any thread). When you receive a chunk, you would copy it into some local <code>MemoryStream</code> and your <code>XmlReader</code> would be reading data from this <code>MemoryStream</code>.</p> <p>This still has a problem though - after copying 10kB of data and calling <code>Read</code> several times, the last call would block. Then you would probably need to copy smaller chunks of data to unblock the pending call to <code>Read</code>. Once that's done, you could again start a new <code>BeginRead</code> call to read larger portion of data asynchronously.</p> <p>Honestly, this sounds pretty complicated, so I'm quite interested if anybody comes up with a better answer. However, it gives you at least some guaranteed asynchronous operations that take some time and do not block any threads in the meantime (which is the essential goal of asynchronous programming).</p> <p>(<strong>Side note:</strong> You could try using <a href="http://www.infoq.com/articles/pickering-fsharp-async" rel="nofollow noreferrer">F# asynchronous workflows</a> to write this, because they make asynchronous code a lot simpler. The technique I described will be tricky even in F# though)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload