Hi guys,
This is sort of related to this post but I wasn't getting any love and I thought this was probably a better place to ask the question... Its a rather long post so I've divided it up a bit. You probably don't need to read the specifics if you don't want to, but I've included them just in case.

THE BASICS: I have a multithreaded application which runs about three threads other than the main app, which have loops along the lines of "while true... end while." When I run the app the CPU usage immediately jumps up to 100% and even though I have the priority on the threads set to 'Lowest' the main application still runs very slowly - the form doesn't redraw regularly, mouse handling is not responsive etc.

THE SPECIFICS: Its basically a chat program being used to run an MSN whiteboard style app. I think the problem occurs in these sections:

a) where the server is waiting on new connections: (fragment)
VB Code:
  1. localListener = New TcpListener(Dns.Resolve(ipHost).AddressList(0), ipPort)
  2.           localListener.Start()
  3.           While (localListener.Pending = False)
  4.                 Thread.Sleep(1000) 'have done this to try and pause the listening thread
  5.           End While
  6.           tClient = localListener.AcceptTcpClient

b) where both the client and server are waiting for transmissions over the TCP socket. (fragment)
VB Code:
  1. While True
  2.                 Dim i As Integer = 0
  3.                    While clientStream.DataAvailable
  4.                         buffer(i) = clientStream.ReadByte
  5.                         i += 1
  6.                     End While
  7.             End While

THE QUESTION:
I guess there are two questions
- Firstly is there a way I make these threads take up less of the processing time, for example taking them out into a separate app which I call at run time as a process?
- If this won't fix it, is there a better way to code the loops so that they don't chew up so much CPU time?