From: Julie on
Perhaps, if I get null, then I can sleep; and if I don't get null, I
won't sleep(?).

From: Julie on
On Jan 22, 12:52 pm, Julie <julievogelm...(a)gmail.com> wrote:
> Perhaps, if I get null, then I can sleep; and if I don't get null, I
> won't sleep(?).

Awesome! I just implemented this, and the CPU's no longer at 100%!

Thanks, everyone, for your ideas.
From: Peter Duniho on
Julie wrote:
> But what if the client takes a break from sending but still has more
> to send? I don't want to stop checking for messages, but I don't want
> to use up CPU either. Hmm...

As you may or may not have figured out by now, there's a big difference
between the end-of-stream, and temporary cessation of data being sent.

If the client "takes a break" by simply not sending more data,
ReadLine() will block. If the client "takes a break" by closing the
connection, then no more data will EVER arrive on that connection, and
ReadLine() will return null. In the latter case, there is no point in
continuing the loop. You'll NEVER see any more data returned by the
ReadLine() method of that instance of StreamReader.

If you have, as you seem to be implying in your subsequent replies,
added a call to Thread.Sleep() to your code, then you have NOT fixed the
problem correctly. You do NOT need Thread.Sleep() in this situation.

Pete
From: Julie on
On Jan 22, 1:06 pm, Peter Duniho <no.peted.s...(a)no.nwlink.spam.com>
wrote:
> Julie wrote:
> > But what if the client takes a break from sending but still has more
> > to send? I don't want to stop checking for messages, but I don't want
> > to use up CPU either. Hmm...
>
> As you may or may not have figured out by now, there's a big difference
> between the end-of-stream, and temporary cessation of data being sent.
>
> If the client "takes a break" by simply not sending more data,
> ReadLine() will block.  If the client "takes a break" by closing the
> connection, then no more data will EVER arrive on that connection, and
> ReadLine() will return null.  In the latter case, there is no point in
> continuing the loop.  You'll NEVER see any more data returned by the
> ReadLine() method of that instance ofStreamReader.
>
> If you have, as you seem to be implying in your subsequent replies,
> added a call to Thread.Sleep() to your code, then you have NOT fixed the
> problem correctly.  You do NOT need Thread.Sleep() in this situation.
>
> Pete


Ahhh...I didn't realize that null meant the client had closed the
connection. Thanks for the clarification.
From: Julie on
Okay, so I've implemented what you recommended (only reading for as
long as inputString != null) - looks good! CPU is normal.