标题:tcpclient.GetStream.beginread回调函数的疑问
只看楼主
picat
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-10-29
 问题点数:0 回复次数:0 
tcpclient.GetStream.beginread回调函数的疑问
有这样一段程序:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim client As TcpClient = New TcpClient("las.sinica.edu.tw", 23)
        Dim reader As StreamReader = New StreamReader(client.GetStream(), Encoding.Default)

        client.GetStream().BeginRead(readBuffer, 0, 255, New AsyncCallback(AddressOf DoRead), Nothing)

        rtxtCmd.Text = client.GetStream().BeginRead(readBuffer, 0, 255, New AsyncCallback(AddressOf DoRead), Nothing).AsyncState
    End Sub
    Private Sub DoRead(ByVal ar As IAsyncResult)
        Dim bytesRead As Integer
        Dim strMessage As String
        Try
            bytesRead = client.GetStream.EndRead(ar)
            If bytesRead < 1 Then
                MessageBox.Show("Disconnected!")
                Exit Sub
            End If
            strMessage = Encoding.ASCII.GetString(readBuffer, 0, bytesRead - 2)
            client.GetStream.BeginRead(readBuffer, 0, 255, New AsyncCallback(AddressOf DoRead), Nothing)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

其中GetStream.beginread方法的回调函数是DoRead,所以每次Form1 load的时候BeginRead方法完成之后会调用DoRead,但是DoRead过程中的BeginRead方法的回调函数也是DoRead,这样不是会陷入死循环吗? 请高手解答,谢谢
搜索更多相关主题的帖子: GetStream beginread tcpclient 回调 函数 
2008-10-29 18:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-241349-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.135033 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved