龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VB开发 >

在vb.net中运用多线程实现远程数据收集[图](5)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
Public Sub New(ByVal sc As TcpClient, ByVal n As NetworkStream, ByVal cn As SqlConnection, ByVal dh As frmServerMain.DelegateHandler1) 由构造函数来初始化成员变量 Me.sck = sc Me.ns = n Me.

Public Sub New(ByVal sc As TcpClient, ByVal n As NetworkStream, ByVal cn As SqlConnection, ByVal dh As frmServerMain.DelegateHandler1) '由构造函数来初始化成员变量

        Me.sck = sc

        Me.ns = n

        Me.sqlcnn = cn

       Me.delg = dh

End Sub 

Public Sub ReadBuff(ByVal state As Object) ' 线程的入口函数

        Dim datastring As String = ""

        ns.ReadTimeout = 100 '读取失败前经历的毫秒数

        Try

            While (True)

                Dim bytes(2048) As Byte

                ns.Read(bytes, 0, 2048)

                datastring = datastring + Encoding.ASCII.GetString(bytes)

                If datastring.IndexOf(vbCrLf) > 0 Then

                    Exit While

                End If

            End While

            delg.Invoke(datastring, sck) '通过委托的方式,将参数传给UI

            Dim tmparr() As String = datastring.Split("##")

            Dim i As Integer

            For i = 0 To tmparr.Length - 1

                If tmparr(i) <> "" Then

                    ProcessInfo(tmparr(i))

                End If

            Next

        Catch ex As System.AccessViolationException

        Catch ex As NotSupportedException

       Catch ex As ArgumentNullException

       Catch ex As ArgumentOutOfRangeException

       Catch ex As ObjectDisposedException

精彩图集

赞助商链接