| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2632 人关注过本帖
标题: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
快速回复:tcpclient.GetStream.beginread回调函数的疑问
数据加载中...
 
   



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

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