469,133 Members | 1,457 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

Making form active when reading from tcpClient

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
Nov 21 '05 #1
2 1227
Hi,

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

http://msdn.microsoft.com/msdnmag/is...s/default.aspx
Ken
-----------------
"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:41**********************@ptn-nntp-reader02.plus.net...
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

Nov 21 '05 #2
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

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:e4*************@TK2MSFTNGP14.phx.gbl...
Hi,

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

http://msdn.microsoft.com/msdnmag/is...s/default.aspx
Ken
-----------------
"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:41**********************@ptn-nntp-reader02.plus.net...
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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Stephen Lamb | last post: by
7 posts views Thread by Roemer | last post: by
2 posts views Thread by Christopher Brandsdal | last post: by
reply views Thread by tshad | last post: by
11 posts views Thread by atlaste | last post: by
1 post views Thread by =?Utf-8?B?RGFydGgtQ3ot?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.