How to use JSON.NET JsonTextReader to read from NetworkStream asynchronously?

I implemented my own NetworkStream port for Silverlight, which allows asynchronous calls.
I would like to read some JSON-RPC messages that I get from the server, so I decided to use JSON.NET JsonTextReader , so I got 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 try to perform a synchronous operation, which in turn simply throws an UnsupportedException .
Is there an asynchronous StreamReader that I can pass to JsonTextReader using? Should I use a different approach?

+4
source share
1 answer

I think you need to. I don’t think you can force JsonTextReader to use an asynchronous approach, but you can change the whole method used to get data for asynchronous behavior. Also use

 using(var io = new StreamReader()) { io.Read(); } 

syntax.

+2
source

All Articles