I'm using this piece of code to process a connection to a server and read data from the client
using(var client = _listener.EndAcceptTcpClient(ar))
{
var clientStream = client.GetStream();
// Get the request message
Messages.ReceiveMessage(clientStream, msg => ProcessRequest(msg, clientStream));
}
Now, the ReceiveMessage method calls BeginRead()
on the Stream passed as a parameter, but I'm getting an ObjectDisposedException.
I know that a solution is to call stream.Dispose() when I don't need the Stream anymore, but I'm really looking for a solution where I can maintain the use of the using
clause.
Thanks