I have problems with Windows 8 UI application. I'm using client-server communication and client needs to check new messages all time. So I use such code, where _socket is a StreamSoket:
private async static void MessageReceiver()
{
var dataReader = new DataReader(_socket.InputStream);
dataReader.InputStreamOptions = InputStreamOptions.Partial;
var stringHeader = await dataReader.LoadAsync(4);
if (stringHeader != 0)
{
var bytes = new byte[4];
dataReader.ReadBytes(bytes);
var length = BitConverter.ToInt32(bytes, 0);
var count = await dataReader.LoadAsync((uint) length);
var result = dataReader.ReadString(count);
ParseRequest(result);
}
dataReader.DetachStream();
MessageReceiver();
}
But in the second LoadAsync, when I try to read the string, I have ObjectDisposedException. Can you help me with it? I have no idea, why such exception is thrown. I've also tried to use DataReader.InputStream.ReadAsync(), but I also had such problem.