A DataSet knows how to serialize to a stream via WriteXml().
I have an object that wants a readable stream. How can I connect the DataSet to this other object?
The plumbing analogy: suppose a 1/2" copper pipe has a "male" outlet, and a valve also has a "male" fitting. To connect the two I need an adapter - female on both ends.
I am imagining an AdapterStream class that is multi-thread-aware. The stream internally is implemented with a fixed buffer, say 8kbytes. On one thread I call WriteXml() using an instance of that AdaterStream. The implementation of WriteXml repeatedly calls Write() to the stream until it's done. But AdapterStream blocks when the buffer is full, and waits until the buffer is drained via a call to Read(). In a separate thread, the app calls Read() on that AdapterStream until it returns zero.
If the buffer is empty that doesn't mean Read() can return zero. It can only return zero when an EOF is signaled by the writing side. (maybe with a Close() or WriteEof() method).
You'd need an ManualResetEvent to be used to signal between the Write() and Read().
It wouldn't be too hard to write. But, does such a thing exist?
Something like the BlockingStream Stephen Taub provided in MSDN Magazine, except without the unlimited buffer allocation.