I implemented my own NetworkStream
port for Silverlight which only allows asynchronous calls.
I would like to read some JSON-RPC messages that I am getting from a server so I figured I'd use JSON.NET JsonTextReader
so I ended up with the following code:
reader = new JsonTextReader(new StreamReader(new NetworkStream(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))));
// ...
reader.Read();
My problem is that it will attempt to perform a synchronous operation which in turn just throw UnsupportedException
.
Is there an asynchronous StreamReader
that I can feed the JsonTextReader
with?
Should I take another approach?
I think you should. I don't think you can force JsonTextReader to use async approach, but you could modify the entire method used for getting data to behave asynchronously. Also, use
using(var io = new StreamReader())
{
io.Read();
}
syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With