J
Julie
So, I currently have code for reading in TCP/IP messages that looks
something like this:
StreamReader reader = new StreamReader(new NetworkStream(mySocket)));
while (true)
{
string inputString = reader.ReadLine();
_newMessages.Enqueue(inputString);
}
This is one thread in my application, and as it is a non-blocking
infinite loop, it is causing my application to consume 100% of my
CPU.
Is there a simple method of rewriting this to cause it to block when
there's nothing else to read? (thereby freeing up CPU)
I attempted to use StreamReader.ReadBlock(), but then realized that
this really doesn't block when the stream is empty either.
Thanks!
something like this:
StreamReader reader = new StreamReader(new NetworkStream(mySocket)));
while (true)
{
string inputString = reader.ReadLine();
_newMessages.Enqueue(inputString);
}
This is one thread in my application, and as it is a non-blocking
infinite loop, it is causing my application to consume 100% of my
CPU.
Is there a simple method of rewriting this to cause it to block when
there's nothing else to read? (thereby freeing up CPU)
I attempted to use StreamReader.ReadBlock(), but then realized that
this really doesn't block when the stream is empty either.
Thanks!