TCPListener / GUI Responsivness

C

Chris Johnson

Hey guys,

A while back I posted a message about multithreading in .NET 2.0 to maintain
GUI responsivness while using a TCPListener to monitor a TCP port for
transmission. One of the MVP's in the group (Cor Ligthert) mentioned using
the queue class to do this.

I have, unfortunatly, been unable to date to figure out how to do this. (I
have achieved the project in a console application, where a GUI isnt
utilized, using the same code I show in my example below.) Does anyone have
an example, or other methods, that I can use to achieve a GUI TCPListener
implementation?

My current implementation revolves around this code (condensed):


Dim server As New TcpListener(localAddr, port)
While True 'Constant Monitor

Dim client As TcpClient = server.AcceptTcpClient()
Dim stream As NetworkStream = client.GetStream()

then break the stream down into bytes and read its contents

End While


Obviously the constant While loop is causing an unresponsive GUI, but I dont
see another way to constantly wait for a TCP message without multithreading,
and if thats the way I need to go I hope someone can provide an example for
me.

Again, thanks for the help,
chrisj
 
G

Guest

Chris said:
Hey guys,

A while back I posted a message about multithreading in .NET 2.0 to maintain
GUI responsivness while using a TCPListener to monitor a TCP port for
transmission. One of the MVP's in the group (Cor Ligthert) mentioned using
the queue class to do this.

I have, unfortunatly, been unable to date to figure out how to do this. (I
have achieved the project in a console application, where a GUI isnt
utilized, using the same code I show in my example below.) Does anyone have
an example, or other methods, that I can use to achieve a GUI TCPListener
implementation?

My current implementation revolves around this code (condensed):


Dim server As New TcpListener(localAddr, port)
While True 'Constant Monitor

Dim client As TcpClient = server.AcceptTcpClient()
Dim stream As NetworkStream = client.GetStream()

then break the stream down into bytes and read its contents

End While


Obviously the constant While loop is causing an unresponsive GUI, but I dont
see another way to constantly wait for a TCP message without multithreading,
and if thats the way I need to go I hope someone can provide an example for
me.

Again, thanks for the help,
chrisj

You should launch your TCP Listener in a separate thread. This way your
GUI has it own thread and will get updates it needs.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top