Making form active when reading from tcpClient

J

Jerry Spence1

I'm having a problem with the following excerpt:

dim tcpCli As New TcpClient

Dim ns As NetworkStream = tcpCli.GetStream

Dim sw As New StreamWriter(ns, System.Text.Encoding.Default)

Dim sr As New StreamReader(ns)

Dim result As String

result = sr.ReadLine

The problem is that the whole form hangs when on the last line, waiting for
an input. I want to have a button so that when waiting for an input, the
user can abort. I've tried threading to no avail. I've also tried
Application.DoEvents() before the read line.

Any ideas?

- Jerry
 
K

Ken Tucker [MVP]

Hi,

Use a seperate thread to prevent the app from locking up while
reading the line of data.

http://msdn.microsoft.com/msdnmag/issues/04/06/BasicInstincts/default.aspx


Ken
-----------------
I'm having a problem with the following excerpt:

dim tcpCli As New TcpClient

Dim ns As NetworkStream = tcpCli.GetStream

Dim sw As New StreamWriter(ns, System.Text.Encoding.Default)

Dim sr As New StreamReader(ns)

Dim result As String

result = sr.ReadLine

The problem is that the whole form hangs when on the last line, waiting for
an input. I want to have a button so that when waiting for an input, the
user can abort. I've tried threading to no avail. I've also tried
Application.DoEvents() before the read line.

Any ideas?

- Jerry
 
J

Jerry Spence1

Thank you for that.

It sort of works, but suddenly I have stopped being able to reference any of
the control properties on my form from within the asynch thread. For example
a textbox will have some text in it, but when I try and read it, it reports
"Nothing" and when I set a button visible, it doesn't have any effect - but
it doesn't object so abviously it is seeing the control OK. The strange
thing is that is was working OK, and it's now stopped and I can't fathom out
what I have done. Everything works from the main thread OK.

- Jerry
 

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