none
Socket 接收(Accept)线程照成CPU100%(原代码) RRS feed

  • 问题

  • Module Module_SubMain
        Public Sub main()
            Application.EnableVisualStyles()
            My.Forms.frm_Main.ShowDialog()
        End Sub
    
    End Module
    Module Module_Vars
    
    #Region "定义结构体"
        Public Structure SocketState
    
            Dim bConnect As Boolean
            Dim sEp As String
        End Structure
    #End Region
        Public sDataServer As String = ""
        Public sDataPassword As String = ""
        Public sDataUser As String = ""
        Public sDataDB As String = ""
        Public lsClass1 As List(Of ClsAcceptClientSocket1)
        Public bActUpCenter As Boolean '是否启用连接上级中心
        Public bConnectUpCenter As Boolean ''是否连接到上级中心、
        Public bLoginUpCenter As Boolean '是否已经登录到上级中心
        Public bStartLinstionEnp As Boolean '是否启用企业端连接的监听
        Public bStartLinstionChk As Boolean '是否启用企业端连接的监听
        Public bStartSearchDB As Boolean '是否启用数据库扫描线程
    End Module
    
    
    #Region "ClsAcceptClientSocket1引用"
    Imports System.Net
    Imports System.Net.Sockets
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Timers
    Imports System.Threading
    #End Region
    
    Public Class ClsAcceptClientSocket1
        Dim bIsBegin As Boolean '是否刚刚开始
        Dim iTimerCheck As Int32 = 0
        Dim itrdSleep As Int16 = 5000
        Dim tSck() As Socket '5个Socket链接
        Dim tmp As Socket
        Dim tTimer As Timers.Timer '时间定时器
        Dim iGet As Int32 = 0 'Socket链接收到的字节留
    
        Dim iSocketUsed As Int32 '已经使用的SOCKET
        Dim iTimerInterval As Int32 '扫描socket状态的时间间隔
        Dim iConnect As Int16 = 0
    
        Dim bOutOfRang As Boolean '是否已经超出限制
    
        Dim dgShowOnListview As frm_Main.ShowMsgOnListView
        Dim tmpBuff() As Byte
        Dim strdName As String
        Dim iAcp As Int32
        Dim trd As Thread '接收数据线程
    
        Dim bStopTrd As Boolean = False
        Dim bConnectDb As Boolean '是否连接到数据库
        Dim SocketStates(4) As SocketState
        Dim sName As String
        'Dim cdb As clsDataBase
        'Dim sckCenter As System.Net.Sockets.Socket = Nothing '上传到总总中心的socket
        'Dim sckUpTo As System.Net.Sockets.Socket = Nothing '上传到报送子系统的socket
        'Dim trdCenter As Thread = Nothing '转送到中心的线程
        'Dim trdUpTo As Thread = Nothing '转送到报送子系统线程
    
        'Dim WithEvents cCenter As Socket = Nothing
        Dim bCheckSocketOK As Boolean = False
        Dim iSockCount As Int16 = 5
    #Region "设置类名"
        Public Property Name() As String
            Get
                Name = sName
            End Get
            Set(ByVal value As String)
                sName = value
            End Set
        End Property
    #End Region
    #Region "设置类名"
        Public Property GetCheckSocketUsed() As Boolean
            Get
                GetCheckSocketUsed = bCheckSocketOK
                bCheckSocketOK = False
            End Get
            Set(ByVal value As Boolean)
    
            End Set
        End Property
    #End Region
    
    #Region "连接详细参数"
        Public Property ConnectInfo() As String
            Get
                Dim scinfo As String = ""
                Dim i As Int16
                For i = 0 To iSockCount - 1
                    If Not (tSck(i)) Is Nothing Then
                        If tSck(i).Connected Then
                            scinfo = scinfo + tSck(i).RemoteEndPoint.ToString() + ";"
                        End If
                    End If
    
                Next
                ConnectInfo = scinfo
            End Get
            Set(ByVal value As String)
    
            End Set
        End Property
    #End Region
    
    #Region "连接上级中心"
        Private Sub ConnectCenter()
            Try
                If bActUpCenter Then
                    Try
                        'cCenter = New clsSendDataToUpperCenter(sRemoteIP, iRemotePort, sRemoteUser, sRemotePass)
                    Catch ex As Exception
                    End Try
                End If
            Catch ex As Exception
            End Try
        End Sub
    #End Region
    #Region "检查总中心连接情况"
        Private Sub CheckPublicCenterConnectState()
            Try
                'If bActUpCenter Then
                '    If bConnectUpCenter Then
                '        If bLoginUpCenter Then
                '        Else
                '            cCenter.ReLogin()
                '        End If
                '    Else
                '        cCenter.ReConnect()
                '    End If
                'End If
            Catch ex As Exception
    
            End Try
        End Sub
    #End Region
    #Region "重设Socket的数量"
        Private Property Sockets() As Int16
            Get
                Sockets = iSockCount
            End Get
            Set(ByVal value As Int16)
                Try
                    If value <= 0 Or value >= 20 Then
                        Exit Property
                    End If
                    If value <> iSockCount Then
                        Dim i As Int16 = 0
                        For i = 0 To iSockCount - 1
                            If Not (Me.tSck(i)) Is Nothing Then
                                Me.tSck(i).Close()
                            End If
                            Me.tSck(i) = Nothing
                            Me.SocketStates(i).bConnect = False
                            Me.SocketStates(i).sEp = ""
                        Next i
                        iSockCount = value
                        ReDim tSck(iSockCount - 1)
    
                        For i = 0 To iSockCount - 1
                            Me.tSck(i) = Nothing
                            Me.SocketStates(i).bConnect = False
                            Me.SocketStates(i).sEp = ""
                        Next i
                        '如果已经开始接收到数据则线程自动休眠5秒钟
                        If bIsBegin = False Then
                            bStopTrd = True
                            Me.dgShowOnListview("测试连接", "无连接," + Me.Name + "线程休眠" + (itrdSleep / 1000).ToString + "秒")
                            'Debug.Print(System.Threading.Thread.CurrentThread.Name.ToString)
                            'System.Threading.Thread.Sleep(itrdSleep)
    
                        End If
                    End If
                Catch ex As Exception
    
                End Try
            End Set
        End Property
    
    
    #End Region
    #Region "使用参数实例化新类"
        Public Sub New(ByVal tmpSocket As Socket, ByVal iScanSocketStateInterval As Int32, _
                       ByVal dShowMsgOnListview As frm_Main.ShowMsgOnListView, ByVal sClassName As String)
            Dim i As Int16 = 0
            Try
                'Me.cdb = New clsDataBase
                'If cdb.OpenDb(sDataServer, sDataUser, sDataPassword, sDataDB) Then
                '    bConnectDb = True
                'Else
                '    bConnectDb = False
                'End If
    
                tTimer = New Timers.Timer
                Me.iTimerInterval = iScanSocketStateInterval
                If (iScanSocketStateInterval) < 0 Or (iScanSocketStateInterval) > 60000 Then
                    Me.iTimerInterval = 60000
                Else
                    iTimerInterval = iScanSocketStateInterval
                End If
                Me.tTimer.Interval = iTimerInterval
                Me.tTimer.AutoReset = True
                Me.tTimer.Enabled = True
                AddHandler tTimer.Elapsed, AddressOf Me.CheckState
                Me.dgShowOnListview = dShowMsgOnListview
    
                Me.sName = sClassName
                ReDim tSck(iSockCount - 1)
                For i = 0 To iSockCount - 1
                    Me.tSck(i) = Nothing
                    Me.SocketStates(i).bConnect = False
                    Me.SocketStates(i).sEp = ""
                Next i
    
                Me.strdName = sClassName
                lsClass1.Add(Me)
                bIsBegin = True
                Me.trd = New Thread(New ThreadStart(AddressOf Me.ReviceMsg))
                Me.trd.Name = sName
                Me.trd.Start()
                Me.trd.IsBackground = True
                'ConnectCenter()
                AcceptSocket(tmpSocket)
            Catch r As NullReferenceException
    
            Catch ex As Exception
    
            End Try
        End Sub
        Public Sub New(ByVal tmpSocket As Socket, ByVal iSocketTotal As Int32, ByVal iScanSocketStateInterval As Int32, _
                       ByVal dShowMsgOnListview As frm_Main.ShowMsgOnListView, ByVal sClassName As String)
            Dim i As Int16 = 0
            Try
                'Me.cdb = New clsDataBase
                'If cdb.OpenDb(sDataServer, sDataUser, sDataPassword, sDataDB) Then
                '    bConnectDb = True
                'Else
                '    bConnectDb = False
                'End If
    
                tTimer = New Timers.Timer
                Me.iTimerInterval = iScanSocketStateInterval
                If (iScanSocketStateInterval) < 0 Or (iScanSocketStateInterval) > 60000 Then
                    Me.iTimerInterval = 60000
                Else
                    iTimerInterval = iScanSocketStateInterval
                End If
                Me.tTimer.Interval = iTimerInterval
                Me.tTimer.AutoReset = True
                Me.tTimer.Enabled = True
                AddHandler tTimer.Elapsed, AddressOf Me.CheckState
                Me.dgShowOnListview = dShowMsgOnListview
    
                Me.sName = sClassName
                If iSocketTotal <= 0 Or iSocketTotal >= 20 Then
                    iSockCount = 4
                End If
                iSockCount = iSocketTotal
                ReDim tSck(iSockCount - 1)
                For i = 0 To iSockCount - 1
                    Me.tSck(i) = Nothing
                    Me.SocketStates(i).bConnect = False
                    Me.SocketStates(i).sEp = ""
                Next i
    
                Me.strdName = sClassName
                lsClass1.Add(Me)
                bIsBegin = True
                Me.trd = New Thread(New ThreadStart(AddressOf Me.ReviceMsg))
                Me.trd.Name = sName
    
                Me.trd.IsBackground = True
                Me.trd.Start()
                'ConnectCenter()
                AcceptSocket(tmpSocket)
            Catch r As NullReferenceException
    
            Catch ex As Exception
    
            End Try
    
    
        End Sub
    #End Region
    
    #Region "接收Socket链接"
        Public Sub AcceptSocket(ByVal tmpSocket As Socket)
            Dim i As Int16 = 0
            Try
                '判断当前线程是否进行休眠() '是唤醒
                If bStopTrd Then
                    bStopTrd = False
                    Me.trd.Interrupt()
                End If
                Dim ic As Int32 = 0
                For i = 0 To iSockCount - 1
                    If tSck(i) Is Nothing Then
                        tSck(i) = New System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                        iSocketUsed = iSocketUsed + 1
                        tSck(i) = tmpSocket
                        tSck(i).SendTimeout = 500
                        While True
                            bIsBegin = False
                            Me.dgShowOnListview("接收Socket", Me.Name + "线程接受" + tSck(i).RemoteEndPoint.ToString() + "连接")
                            SocketStates(i).bConnect = tSck(i).Connected
                            SocketStates(i).sEp = tmpSocket.RemoteEndPoint.ToString
                            ReviceMsg()
    
                            Exit For
                        End While
                    End If
                Next
    
            Catch ex As Exception
                iSocketUsed = 0
            End Try
        End Sub
    #End Region
    #Region "解析数据包"
        Private Sub ReviceMsg()
            Dim i As Int16
            Dim tB As Integer = 0
            Dim tby() As Byte
            Dim sGet As String = ""
            Dim sRet As String = ""
            Try
                While (True)
                    iSocketUsed = 0
                    For i = 0 To iSockCount - 1
                        tB = 0
                        ReDim tby(10240)
                        Try
                            If Not (tSck(i)) Is Nothing Then
                                Try
                                    tB = tSck(i).Receive(tby, SocketFlags.None)
                                    iSocketUsed = iSocketUsed + 1
                                    SocketStates(i).bConnect = True
                                    SocketStates(i).sEp = tSck(i).RemoteEndPoint.ToString
                                Catch ex As Exception
                                    Me.dgShowOnListview("关闭连接", Me.Name + "线程关闭" + SocketStates(i).sEp + "连接")
                                    tSck(i) = Nothing
                                    SocketStates(i).bConnect = False
                                    SocketStates(i).sEp = ""
                                End Try
                            Else
                                SocketStates(i).bConnect = False
                                SocketStates(i).sEp = ""
                            End If
    
                            If tB > 0 Then
                                sGet = System.Text.Encoding.ASCII.GetString(tby, 0, tB)
                                Me.dgShowOnListview("接收到数据", sGet)
    
                                Dim by() As Byte = System.Text.Encoding.ASCII.GetBytes("%01#OKtestOKtestOKtestOKtestOKtest" + "0")
                                Try
                                    tSck(i).Send(by)
                                Catch ex As SocketException
                                    Me.dgShowOnListview("回应数据失败", Me.Name + "线程关闭" + SocketStates(i).sEp + "连接")
                                    Me.tSck(i) = Nothing
                                    SocketStates(i).bConnect = False
                                    SocketStates(i).sEp = ""
                                Catch ex As Exception
                                    Me.dgShowOnListview("回应数据失败", Me.Name + "线程关闭" + SocketStates(i).sEp + "连接")
                                    Me.tSck(i) = Nothing
                                    SocketStates(i).bConnect = False
                                    SocketStates(i).sEp = ""
                                End Try
                                Try
                                    '发送到总中心()
                                    'If Not (cCenter) Is Nothing Then
                                    '    cCenter.SendMsg(sGet, sRet)
                                    'End If
                                Catch ex As Exception
                                End Try
                                Try
                                    '发送到转发中心
                                Catch ex As Exception
                                End Try
                            End If
                        Catch ex As SocketException
                            tSck(i) = Nothing
                        Catch ex As ThreadAbortException
                        Catch ex As ThreadStateException
                        Catch r As NullReferenceException
                            Debug.Print(r.Message)
                        Catch ex As Exception
                        End Try
                    Next
                    If iSocketUsed = iSockCount Then
                        bOutOfRang = True
                    Else
                        bOutOfRang = False
                    End If
                    If iSocketUsed = 0 Then
                        '如果则线程自动休眠5秒钟
                        If bIsBegin = False Then
                            bStopTrd = True
                            Me.dgShowOnListview("检测连接", "无连接," + System.Threading.Thread.CurrentThread.Name + "线程休眠" + (itrdSleep / 1000).ToString + "秒")
                            trd.Sleep(itrdSleep)
                            Exit While
                        End If
                    End If
                End While
    
            Catch ex As ThreadAbortException
    
            Catch ex As Exception
    
                iSocketUsed = 0
                For i = 0 To iSockCount - 1
                    If Not tSck(i) Is Nothing Then
                        If tSck(i).Connected Then
                            SocketStates(i).bConnect = True
                            iSocketUsed = iSocketUsed + 1
                            If tSck(i).Connected Then
                                SocketStates(i).sEp = tSck(i).RemoteEndPoint.ToString
                            End If
                        Else
                            SocketStates(i).sEp = ""
                            SocketStates(i).bConnect = False
                        End If
                    Else
                        SocketStates(i).sEp = ""
                        SocketStates(i).bConnect = False
                    End If
                Next
                If iSocketUsed = iSockCount Then
                    bOutOfRang = True
                Else
                    bOutOfRang = False
                End If
                If iSocketUsed = 0 Then
                    ''如果没有连接则清除线程
                    'bStopTrd = True
                    'Try
                    '    If bIsBegin = False Then
                    '        bStopTrd = True
                    '        Me.dgShowOnListview("无连接,线程休眠" + (itrdSleep / 1000).ToString + "秒")
                    '        System.Threading.Thread.Sleep(itrdSleep)
                    '    End If
    
                    'Catch r As NullReferenceException
    
                    'Catch ex1 As Exception
                    'End Try
                End If
            End Try
        End Sub
    #End Region
    #Region "定时检查各个Socket的连接状态和数据库状态"
        Private Sub CheckState(ByVal Sender As Object, ByVal e As Timers.ElapsedEventArgs)
            Dim i As Int16
            iTimerCheck = iTimerCheck + 1
            '测试当前连接是否正常(没5扁次检查一扁)
            Me.dgShowOnListview("线程定时检测", Me.Name + "线程状态自检 " + "...")
            If iTimerCheck >= 5 Then
                'Me.dgShowOnListview("线程定时检测", "测试数据库连接 " + "...")
                'If cdb.TestConnState() Then
                '    Me.bConnectDb = True
                '    Me.dgShowOnListview("线程定时检测", "数据库连接 " + "正常")
                'Else
                '    Me.bConnectDb = False
                '    Me.dgShowOnListview("线程定时检测", "数据库连接 " + "异常")
                'End If
                iTimerCheck = 0
            End If
    
            iSocketUsed = 0
            Me.dgShowOnListview("线程定时检测", Me.Name + "线程测试Socket连接 " + "...")
            '发送检测数据包'发送成功表示连接成功,否则表示失败,取消连接
            'Dim by() As Byte = System.Text.Encoding.UTF8.GetBytes("System On Time Checking")
            Dim by() As Byte = System.Text.Encoding.UTF8.GetBytes("%01#WCSRDENG**")
            For i = 0 To iSockCount - 1
                Try
                    If Not (tSck(i)) Is Nothing Then
                        tSck(i).Send(by)
                        SocketStates(i).bConnect = True
                        iSocketUsed = iSocketUsed + 1
                        SocketStates(i).sEp = tSck(i).RemoteEndPoint.ToString
                    End If
                    'tSck(i).Send(by)
    
                Catch ex As NullReferenceException
                    tSck(i) = Nothing
                    Me.dgShowOnListview("线程定时检测", Me.Name + "线程清除资源")
                    Me.tSck(i) = Nothing
                    SocketStates(i).sEp = ""
                    SocketStates(i).bConnect = False
                Catch ex As SocketException
                    Me.dgShowOnListview("线程定时检测", Me.Name + "线程关闭" + SocketStates(i).sEp.ToString() + "连接")
                    Me.tSck(i) = Nothing
                    SocketStates(i).sEp = ""
                    SocketStates(i).bConnect = False
                Catch ex As Exception
                    Me.dgShowOnListview("线程定时检测", Me.Name + "线程关闭" + SocketStates(i).sEp.ToString() + "连接")
                    Me.tSck(i) = Nothing
                    SocketStates(i).sEp = ""
                    SocketStates(i).bConnect = False
                End Try
    
            Next
            '检查总中心连接情况
            If iSocketUsed = iSockCount Then
                bOutOfRang = True
            Else
                bOutOfRang = False
            End If
            CheckPublicCenterConnectState()
    
        End Sub
    #End Region
    #Region "设置类的属性,链接数量"
        Public Property SocketUsed() As Int32
            Get
                SocketUsed = iSocketUsed
            End Get
            Set(ByVal value As Int32)
    
            End Set
        End Property
    #End Region
    #Region "设置类的属性,检查连接"
        Public Property CheckSocketUsed() As Boolean
            Get
    
            End Get
            Set(ByVal value As Boolean)
    
                If value Then
                    Dim by() As Byte = System.Text.Encoding.UTF8.GetBytes("Check Connect")
                    bCheckSocketOK = False
                    Dim i As Int32
                    Me.dgShowOnListview("线程接收连接前检测", "测试Socket连接 " + "...")
                    For i = 0 To iSockCount - 1
                        '发送检测数据包'发送成功表示连接成功,否则表示失败,取消连接
                        Try
                            If Not (tSck(i)) Is Nothing Then
                                tSck(i).Send(by)
                            End If
                        Catch r As NullReferenceException
                            Me.dgShowOnListview("线程接收连接前检测", "系统关闭" + SocketStates(i).sEp.ToString() + "连接")
                            tSck(i) = Nothing
                            SocketStates(i).sEp = ""
                            SocketStates(i).bConnect = False
                        Catch ex As SocketException
                            Me.dgShowOnListview("线程接收连接前检测", "系统关闭" + SocketStates(i).sEp.ToString() + "连接")
                            tSck(i) = Nothing
                            SocketStates(i).sEp = ""
                            SocketStates(i).bConnect = False
                        Catch ex As Exception
                            Me.dgShowOnListview("线程接收连接前检测", "系统关闭" + SocketStates(i).sEp.ToString() + "连接")
                            tSck(i) = Nothing
                            SocketStates(i).sEp = ""
                            SocketStates(i).bConnect = False
                        End Try
                    Next
                    bCheckSocketOK = True
                End If
            End Set
        End Property
    #End Region
    #Region "设置类的属性,检查连接"
        Public Property ClearTrd() As Boolean
            Get
    
            End Get
            Set(ByVal value As Boolean)
                If value Then
                    Finalize()
                End If
            End Set
        End Property
    #End Region
    #Region "是否已经超出限制"
        Public Property OutOfRang() As Boolean
            Get
                OutOfRang = bOutOfRang
            End Get
            Set(ByVal value As Boolean)
    
            End Set
        End Property
    
    #End Region
    
    #Region "释放资源"
        Protected Overrides Sub Finalize()
    
            Try
                tTimer.Enabled = False
                RemoveHandler tTimer.Elapsed, AddressOf Me.CheckState
                Dim i As Int16
                For i = 0 To iSockCount - 1
                    If Not (tSck(i)) Is Nothing Then
                        tSck(i).Shutdown(SocketShutdown.Both)
                        tSck(i).Close(0)
                    End If
                    tSck(i) = Nothing
                Next
                Try
                    trd.Interrupt()
                    trd.Abort()
                Catch ex As Exception
                End Try
                trd = Nothing
                'Me.cdb = Nothing
                'Me.tSqlCnn = Nothing
                tTimer = Nothing
            Catch ex As Exception
                trd = Nothing
                'Me.tSqlCnn.Close()
                'Me.cdb = Nothing
                tTimer = Nothing
            End Try
    
            ' MyBase.Finalize()
    
        End Sub
    #End Region
    #Region "清除数据"
        Public Sub Disposed(Optional ByVal b As Boolean = True)
            Try
                tTimer.Enabled = False
                RemoveHandler tTimer.Elapsed, AddressOf Me.CheckState
                Dim i As Int16
                For i = 0 To iSockCount - 1
                    If Not (tSck(i)) Is Nothing Then
                        tSck(i).Shutdown(SocketShutdown.Both)
                        tSck(i).Close(0)
                    End If
                    tSck(i) = Nothing
                Next
                Try
                    trd.Interrupt()
                    trd.Abort()
                Catch ex As Exception
                End Try
                trd = Nothing
                'Me.cdb = Nothing
                'Me.tSqlCnn = Nothing
                tTimer = Nothing
            Catch ex As Exception
                trd = Nothing
                'Me.tSqlCnn.Close()
                'Me.cdb = Nothing
                tTimer = Nothing
            End Try
    
        End Sub
    #End Region
    #Region "保存数据"
    
    #End Region
    
    End Class
    
    #Region "ClsSocketListion引用"
    Imports System.Net
    Imports System.Net.Sockets
    Imports System.Threading
    #End Region
    
    Public Class ClsSocketListion
        Dim sListion As TcpListener = Nothing
        Dim TrdLin As Thread = Nothing
        Dim Ep As IPEndPoint = Nothing
        Dim tTimer As System.Timers.Timer = Nothing
        Dim TmpSocket As Socket
        Dim sIp As String = ""
        Dim iPort As Int32
        Dim BLinstioning As Boolean '是否正在监听
        Dim sName As String = "TcpLinstion"
    
        Public Event ConnectionRequest(ByRef AcceptedSocket As Socket)
        Public Event StateEvents(ByVal sEvents As String, ByVal sData As String)
    
    #Region "定时检测监听线程是否在监听"
        Private Sub TimerTick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
    
        End Sub
    #End Region
    #Region "设置参数IP"
        Public Property LocalIP() As String
            Get
                Try
                    If Not (Ep) Is Nothing Then
                        Return Ep.Address.ToString
                    Else
                        Return ""
                    End If
                Catch ex As Exception
                    Return ""
                End Try
            End Get
            Set(ByVal value As String)
                sIp = value
            End Set
        End Property
    #End Region
    #Region "设置类的名称"
        Public Property Name() As String
            Get
                Return sName
            End Get
            Set(ByVal value As String)
                sName = value
            End Set
        End Property
    #End Region
    #Region "设置参数端口"
        Public Property LocalPort() As Int32
            Get
                Try
                    If Not (Ep) Is Nothing Then
                        Return Ep.Port
                    End If
                Catch ex As Exception
                    Return -1
                End Try
            End Get
            Set(ByVal value As Int32)
                If (value > 65000) Or (value < 1) Then
                    Exit Property
                End If
                iPort = value
            End Set
        End Property
    #End Region
    #Region "IPEndPort"
        Public Property BindIPEndPoint() As IPEndPoint
            Get
                Return Ep
            End Get
            Set(ByVal value As IPEndPoint)
                Ep = value
            End Set
        End Property
    #End Region
    #Region "开始监听"
        Public Sub StartLinstion(ByVal ep1 As IPEndPoint)
            If (Ep Is Nothing) And (ep1 Is Nothing) Then
                BLinstioning = False
                Exit Sub
            End If
            If Not (ep1) Is Nothing Then
                Ep = ep1
                StrartTrd()
            End If
        End Sub
        Public Sub StartLinstion()
            Try
                If (Ep Is Nothing) Then
                    BLinstioning = False
                    Exit Sub
                End If
                StrartTrd()
            Catch ex As Exception
    
            End Try
    
        End Sub
    #End Region
    #Region "重新开始监听"
        Public Sub ReStartListion()
            StartLinstion()
        End Sub
    #End Region
    #Region "启动监听线程"
        Private Sub StrartTrd()
            TrdLin = New Thread(New ThreadStart(AddressOf IniListion))
            TrdLin.Name = sName
            TrdLin.IsBackground = True
            TrdLin.Start()
            RaiseEvent StateEvents("监听器状态", "监听器正在启动")
        End Sub
    #End Region
    #Region "监听线程"
        Private Sub IniListion()
            Try
                sListion = Nothing
                System.Threading.Thread.Sleep(500)
                sListion = New TcpListener(Ep)
                sListion.Start()
                While (True)
                    Try
                        TmpSocket = sListion.AcceptSocket
                        If Not (TmpSocket) Is Nothing Then
                            '关闭监听
                            sListion.Stop()
                            'RaiseEvent StateEvents("监听器状态", "监听器已经停止监听")
                            '触发重定向事件
                            RaiseEvent ConnectionRequest(TmpSocket)
                            'TrdLin.Abort()
                            'TrdLin = Nothing
                            System.Threading.Thread.Sleep(200)
                            sListion.Start()
                            'StartLinstion()
                        End If
                    Catch ex As Exception
    
                    End Try
    
                End While
            Catch ex As Exception
                Thread.Sleep(500)
                IniListion()
            End Try
        End Sub
    #End Region
    #Region "释放资源"
        Public Sub Disposed(ByVal bAct As Boolean)
            Try
                Ep = Nothing
                If Not (TrdLin) Is Nothing Then
                    If TrdLin.IsAlive Then
                        TrdLin.Abort()
                    End If
                End If
                TrdLin = Nothing
            Catch ex As Exception
                TrdLin = Nothing
                sListion = Nothing
            End Try
        End Sub
    #End Region
    #Region "监听状态"
        Public Property LinstionState() As Boolean
            Get
                LinstionState = BLinstioning
            End Get
            Set(ByVal value As Boolean)
    
            End Set
        End Property
    #End Region
    End Class
    
    Public Class frm_Main
        Dim iTimerCount As Int32 = 0
        Dim iSystemEventsCount As Int32 = 0
        Dim iMonrEventsCount As Int32 = 0
        Dim iCheckEventsCount As Int32 = 0
        Public Delegate Sub ShowMsgOnListView(ByVal sEvents As String, ByVal sData As String)
        Dim WithEvents c As ClsSocketListion
        Dim iEnpLink As Int32 = 0
        Dim TrdAckEnp As Threading.Thread = Nothing
        Dim TmpSocket As Net.Sockets.Socket = Nothing
        Dim bEnpAcceptOK As Boolean '是否接收完毕(企业)
        Dim bChkAcceptOK As Boolean '是否接收完毕(审核)
    #Region "递归循环清楚已经是Nothing的lsClass1对象"
        Private Sub clearLsClass1(ByVal iC As Int32)
            Try
                If iC >= 0 Then
                    iC = -1
                    For i As Int32 = 0 To lsClass1.Count - 1
                        If lsClass1(i) Is Nothing Then
                            iC = i
                            lsClass1.RemoveAt(i)
                            Exit For
                        End If
                    Next
                    clearLsClass1(iC)
                End If
            Catch ex As Exception
    
            End Try
    
    
        End Sub
    #End Region
    
    #Region " 该timer的时间敬间隔为1000MS=1秒 ‘主要用于检测数据库连接"
    
        Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Try
                iTimerCount = iTimerCount + 1
                If iTimerCount Mod 60 = 0 Then
                    ShowMsgOnSystemEventListView("定时检查", "检查各个线程状态")
                    For i As Int32 = 0 To lsClass1.Count - 1
                        lsClass1(i).CheckSocketUsed = True
                    Next
                    While True
                        Dim ik As Int32 = 0
                        Dim iIndex As Int32 = -1
    
                        For i As Int32 = 0 To lsClass1.Count - 1
                            If lsClass1(i).GetCheckSocketUsed Then
                                ik = ik + 1
                            End If
                        Next
                        If ik = lsClass1.Count Then
                            Exit While
                        End If
                    End While
                    For i As Int32 = 0 To lsClass1.Count - 1
                        If lsClass1(i).SocketUsed = 0 Then
                            ShowMsgOnSystemEventListView("检查结果", "清除企业端接收线程" + lsClass1(i).Name)
                            lsClass1(i).Disposed(True)
                            lsClass1(i) = Nothing
                        End If
                    Next
                    'clearLsClass1(1)
                    Dim s1 As New List(Of ClsAcceptClientSocket1)
                    For i As Int32 = 0 To lsClass1.Count - 1
                        If Not (lsClass1(i)) Is Nothing Then
                            s1.Add(lsClass1(i))
                        End If
                    Next
                    lsClass1.Clear()
                    'Dim s1 As New List(Of ClsAcceptClientSocket1)
                    For i As Int32 = 0 To s1.Count - 1
                        lsClass1.Add(s1(i))
                    Next
                End If
                If iTimerCount >= 1800 Then
                    iTimerCount = 0
                    ShowMsgOnSystemEventListView("定时检查", "检查数据库连接")
                    'Dim cDB As New clsDataBase
                    'If cDB.OpenDb(".", "sa", "", "QYGLPT") Then
                    '    ShowMsgOnSystemEventListView("测试数据库", "数据库连接正常")
                    '    Me.la_Data.Text = "正常"
                    'Else
                    '    ShowMsgOnSystemEventListView("测试数据库", "数据库连接异常")
                    '    Me.la_Data.Text = "异常"
                    'End If
                    'cDB.Disposed()
                    'cDB = Nothing
                End If
            Catch ex As Exception
    
            End Try
    
    
        End Sub
    #End Region
    #Region "向系统事件的列表添加数据"
        Private Sub ShowMsgOnSystemEventListView(ByVal sEvents As String, ByVal sData As String)
            Try
                Dim ds As New ShowMsgOnListView(AddressOf AddDataToSystemEventListView)
                Me.LVSystem.Invoke(ds, sEvents, sData)
            Catch ex As Exception
    
            End Try
        End Sub
        Private Sub AddDataToSystemEventListView(ByVal sEvents As String, ByVal sData As String)
            Try
                iSystemEventsCount = iSystemEventsCount + 1
                If iSystemEventsCount >= 200 Then
                    iSystemEventsCount = 0
                    Me.LVSystem.Items.Clear()
                End If
                Dim ite As ListViewItem = Me.LVSystem.Items.Insert(0, System.DateTime.Now.ToString("MM-dd HH:mm:ss"))
                ite.SubItems.Add(sEvents)
                ite.SubItems.Add(sData)
            Catch ex As Exception
    
            End Try
    
    
        End Sub
    #End Region
    #Region "系统启动后启动各个线程"
        Private Sub frm_Main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try
                lsClass1 = New List(Of ClsAcceptClientSocket1)
                Me.La_Time.Text = Format(Now, "yy-MM-dd HH:mm:ss")
                AddDataToSystemEventListView("系统启动", "初始化各个线程")
                sDataServer = "."
                sDataUser = "sa"
                sDataPassword = ""
                sDataDB = "QYGLPT"
                Try
                    'Dim cDB As New clsDataBase
                    'If cDB.OpenDb(sDataServer, sDataUser, sDataPassword, sDataDB) Then
                    '    AddDataToSystemEventListView("测试数据库", "数据库连接正常")
                    '    Me.la_Data.Text = "正常"
                    'Else
                    '    AddDataToSystemEventListView("测试数据库", "数据库连接异常")
                    '    Me.la_Data.Text = "异常"
                    'End If
                    'cDB.Disposed()
                    'cDB = Nothing
                Catch ex As Exception
    
                End Try
                Try
                    c = New ClsSocketListion()
                    c.Name = "监控点监听器"
                    Dim ep As New Net.IPEndPoint(Net.IPAddress.Parse("10.119.1.17"), 5600)
                    c.StartLinstion(ep)
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            Catch ex As Exception
    
            End Try
        End Sub
    #End Region
    #Region "显示接收到的数据"
        Private Sub ShowSocketMsg(ByVal sEvents As String, ByVal sData As String)
            Dim ds As New ShowMsgOnListView(AddressOf Me.AddDataToEnpSocketEvents)
            Me.LvMont.Invoke(ds, sEvents, sData)
        End Sub
        Private Sub AddDataToEnpSocketEvents(ByVal sEvents As String, ByVal sData As String)
            Try
                iMonrEventsCount = iMonrEventsCount + 1
                If iMonrEventsCount >= 200 Then
                    iMonrEventsCount = 0
                    Me.LvMont.Items.Clear()
                End If
                Dim ite As ListViewItem = Me.LvMont.Items.Insert(0, System.DateTime.Now.ToString("MM-dd HH:mm:ss"))
                ite.SubItems.Add(sEvents)
                ite.SubItems.Add(sData)
            Catch ex As Exception
    
            End Try
        End Sub
    
    
    #End Region
    #Region "使用新的现成进行接收处理,住线程继续监听"
        Private Sub NewTrd()
            If Not (TmpSocket) Is Nothing Then
                If lsClass1.Count = 0 Then
                    iEnpLink = iEnpLink + 1
                    bEnpAcceptOK = True
                    Dim delg As New ShowMsgOnListView(AddressOf Me.ShowSocketMsg)
                    Dim c1 As New ClsAcceptClientSocket1(TmpSocket, 30000, delg, "EnpSocketLink" + iEnpLink.ToString)
                    TmpSocket = Nothing
                Else
                    Dim iij As Int32 = 0
                    For i As Int32 = 0 To lsClass1.Count - 1
                        If Not (lsClass1(i)) Is Nothing Then
                            lsClass1(i).CheckSocketUsed = True
                            iij = iij + 1
                        End If
    
                    Next
                    While True
                        Dim ik As Int32 = 0
                        Dim iIndex As Int32 = -1
                        For i As Int32 = 0 To lsClass1.Count - 1
                            If Not (lsClass1(i)) Is Nothing Then
                                If lsClass1(i).GetCheckSocketUsed Then
                                    ik = ik + 1
                                End If
                            End If
    
                        Next
                        If ik = iij Then
                            For i As Int32 = 0 To lsClass1.Count - 1
                                If Not (lsClass1(i)) Is Nothing Then
                                    If lsClass1(i).OutOfRang = False Then
                                        iIndex = i
                                        Exit For
                                    End If
                                End If
    
                            Next
                            If iIndex <> -1 Then
                                lsClass1(iIndex).AcceptSocket(TmpSocket)
                                TmpSocket = Nothing
                            Else
                                Exit While
                            End If
                        End If
                    End While
                    iEnpLink = iEnpLink + 1
                    bEnpAcceptOK = True
                    Dim delg As New ShowMsgOnListView(AddressOf Me.ShowSocketMsg)
                    Dim c1 As New ClsAcceptClientSocket1(TmpSocket, 30000, delg, "EnpSocketLink" + iEnpLink.ToString)
                End If
            End If
        End Sub
    #End Region
        Private Sub c_ConnectionRequest(ByRef AcceptedSocket As System.Net.Sockets.Socket) Handles c.ConnectionRequest
            Try
                ShowMsgOnSystemEventListView("接收企业端连接", "接收" + AcceptedSocket.RemoteEndPoint.ToString + "的链接")
                TmpSocket = AcceptedSocket
    
                TrdAckEnp = New Threading.Thread(New Threading.ThreadStart(AddressOf NewTrd))
                TrdAckEnp.Name = "间接接收数据线程"
                TrdAckEnp.IsBackground = True
                TrdAckEnp.Start()
                System.Threading.Thread.Sleep(500)
                TmpSocket = Nothing
                Try
    
                Catch ex As Exception
    
                End Try
            Catch ex As Exception
    
            End Try
        End Sub
    
        Private Sub c_StateEvents(ByVal sEvents As String, ByVal sData As String) Handles c.StateEvents
            Try
                ShowMsgOnSystemEventListView(c.Name + sEvents, sData)
            Catch ex As Exception
    
            End Try
    
        End Sub
    End Class
    
    2009年8月20日 8:02

全部回复

  • <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class frm_Main
        Inherits System.Windows.Forms.Form
    
        'Form 重写 Dispose,以清理组件列表。
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
            MyBase.Dispose(disposing)
        End Sub
    
        'Windows 窗体设计器所必需的
        Private components As System.ComponentModel.IContainer
    
        '注意: 以下过程是 Windows 窗体设计器所必需的
        '可以使用 Windows 窗体设计器修改它。
        '不要使用代码编辑器修改它。
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Me.components = New System.ComponentModel.Container
            Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frm_Main))
            Me.MenuStrip1 = New System.Windows.Forms.MenuStrip
            Me.系统ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
            Me.关于ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem
            Me.SplitContainer1 = New System.Windows.Forms.SplitContainer
            Me.GroupBox5 = New System.Windows.Forms.GroupBox
            Me.C1Sizer1 = New C1.Win.C1Sizer.C1Sizer
            Me.TreeView1 = New System.Windows.Forms.TreeView
            Me.Button1 = New System.Windows.Forms.Button
            Me.SplitContainer3 = New System.Windows.Forms.SplitContainer
            Me.GroupBox4 = New System.Windows.Forms.GroupBox
            Me.C1Sizer2 = New C1.Win.C1Sizer.C1Sizer
            Me.Button19 = New System.Windows.Forms.Button
            Me.Button18 = New System.Windows.Forms.Button
            Me.Button17 = New System.Windows.Forms.Button
            Me.Button16 = New System.Windows.Forms.Button
            Me.Button15 = New System.Windows.Forms.Button
            Me.Button14 = New System.Windows.Forms.Button
            Me.Button13 = New System.Windows.Forms.Button
            Me.Button12 = New System.Windows.Forms.Button
            Me.Button11 = New System.Windows.Forms.Button
            Me.Button10 = New System.Windows.Forms.Button
            Me.Button9 = New System.Windows.Forms.Button
            Me.Button8 = New System.Windows.Forms.Button
            Me.Button7 = New System.Windows.Forms.Button
            Me.Button6 = New System.Windows.Forms.Button
            Me.Button5 = New System.Windows.Forms.Button
            Me.Button4 = New System.Windows.Forms.Button
            Me.Button3 = New System.Windows.Forms.Button
            Me.Button2 = New System.Windows.Forms.Button
            Me.C1Sizer3 = New C1.Win.C1Sizer.C1Sizer
            Me.GroupBox3 = New System.Windows.Forms.GroupBox
            Me.LVCheck = New System.Windows.Forms.ListView
            Me.ColumnHeader4 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader5 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader6 = New System.Windows.Forms.ColumnHeader
            Me.GroupBox2 = New System.Windows.Forms.GroupBox
            Me.LVSystem = New System.Windows.Forms.ListView
            Me.ColumnHeader7 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader8 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader9 = New System.Windows.Forms.ColumnHeader
            Me.GroupBox1 = New System.Windows.Forms.GroupBox
            Me.LvMont = New System.Windows.Forms.ListView
            Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader
            Me.StatusStrip1 = New System.Windows.Forms.StatusStrip
            Me.ToolStripStatusLabel1 = New System.Windows.Forms.ToolStripStatusLabel
            Me.La_Time = New System.Windows.Forms.ToolStripStatusLabel
            Me.ToolStripStatusLabel3 = New System.Windows.Forms.ToolStripStatusLabel
            Me.la_Data = New System.Windows.Forms.ToolStripStatusLabel
            Me.ToolStripStatusLabel5 = New System.Windows.Forms.ToolStripStatusLabel
            Me.la_Enp = New System.Windows.Forms.ToolStripStatusLabel
            Me.ToolStripStatusLabel7 = New System.Windows.Forms.ToolStripStatusLabel
            Me.lz_Check = New System.Windows.Forms.ToolStripStatusLabel
            Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
            Me.MenuStrip1.SuspendLayout()
            Me.SplitContainer1.Panel1.SuspendLayout()
            Me.SplitContainer1.Panel2.SuspendLayout()
            Me.SplitContainer1.SuspendLayout()
            Me.GroupBox5.SuspendLayout()
            CType(Me.C1Sizer1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.C1Sizer1.SuspendLayout()
            Me.SplitContainer3.Panel1.SuspendLayout()
            Me.SplitContainer3.Panel2.SuspendLayout()
            Me.SplitContainer3.SuspendLayout()
            Me.GroupBox4.SuspendLayout()
            CType(Me.C1Sizer2, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.C1Sizer2.SuspendLayout()
            CType(Me.C1Sizer3, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.C1Sizer3.SuspendLayout()
            Me.GroupBox3.SuspendLayout()
            Me.GroupBox2.SuspendLayout()
            Me.GroupBox1.SuspendLayout()
            Me.StatusStrip1.SuspendLayout()
            Me.SuspendLayout()
            '
            'MenuStrip1
            '
            Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.系统ToolStripMenuItem, Me.关于ToolStripMenuItem})
            Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
            Me.MenuStrip1.Name = "MenuStrip1"
            Me.MenuStrip1.Size = New System.Drawing.Size(1012, 24)
            Me.MenuStrip1.TabIndex = 0
            Me.MenuStrip1.Text = "MenuStrip1"
            '
            '系统ToolStripMenuItem
            '
            Me.系统ToolStripMenuItem.Name = "系统ToolStripMenuItem"
            Me.系统ToolStripMenuItem.Size = New System.Drawing.Size(41, 20)
            Me.系统ToolStripMenuItem.Text = "系统"
            '
            '关于ToolStripMenuItem
            '
            Me.关于ToolStripMenuItem.Name = "关于ToolStripMenuItem"
            Me.关于ToolStripMenuItem.Size = New System.Drawing.Size(41, 20)
            Me.关于ToolStripMenuItem.Text = "关于"
            '
            'SplitContainer1
            '
            Me.SplitContainer1.Dock = System.Windows.Forms.DockStyle.Fill
            Me.SplitContainer1.Location = New System.Drawing.Point(0, 24)
            Me.SplitContainer1.Name = "SplitContainer1"
            '
            'SplitContainer1.Panel1
            '
            Me.SplitContainer1.Panel1.Controls.Add(Me.GroupBox5)
            '
            'SplitContainer1.Panel2
            '
            Me.SplitContainer1.Panel2.Controls.Add(Me.SplitContainer3)
            Me.SplitContainer1.Size = New System.Drawing.Size(1012, 660)
            Me.SplitContainer1.SplitterDistance = 337
            Me.SplitContainer1.TabIndex = 3
            '
            'GroupBox5
            '
            Me.GroupBox5.Controls.Add(Me.C1Sizer1)
            Me.GroupBox5.Dock = System.Windows.Forms.DockStyle.Fill
            Me.GroupBox5.Location = New System.Drawing.Point(0, 0)
            Me.GroupBox5.Name = "GroupBox5"
            Me.GroupBox5.Size = New System.Drawing.Size(337, 660)
            Me.GroupBox5.TabIndex = 0
            Me.GroupBox5.TabStop = False
            Me.GroupBox5.Text = "监控点连接列表"
            '
            'C1Sizer1
            '
            Me.C1Sizer1.Controls.Add(Me.TreeView1)
            Me.C1Sizer1.Controls.Add(Me.Button1)
            Me.C1Sizer1.Dock = System.Windows.Forms.DockStyle.Fill
            Me.C1Sizer1.GridDefinition = "4.6875:False:False;93.4375:False:False;" & Global.Microsoft.VisualBasic.ChrW(9) & "46.8277945619335:False:True;49.5468277945" & _
                "619:False:False;"
            Me.C1Sizer1.ImeMode = System.Windows.Forms.ImeMode.NoControl
            Me.C1Sizer1.Location = New System.Drawing.Point(3, 17)
            Me.C1Sizer1.Name = "C1Sizer1"
            Me.C1Sizer1.Size = New System.Drawing.Size(331, 640)
            Me.C1Sizer1.TabIndex = 0
            Me.C1Sizer1.TabStop = False
            '
            'TreeView1
            '
            Me.TreeView1.Location = New System.Drawing.Point(4, 38)
            Me.TreeView1.Name = "TreeView1"
            Me.TreeView1.Size = New System.Drawing.Size(323, 598)
            Me.TreeView1.TabIndex = 1
            '
            'Button1
            '
            Me.Button1.Location = New System.Drawing.Point(4, 4)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(155, 30)
            Me.Button1.TabIndex = 0
            Me.Button1.Text = "刷新"
            Me.Button1.UseVisualStyleBackColor = True
            '
            'SplitContainer3
            '
            Me.SplitContainer3.Dock = System.Windows.Forms.DockStyle.Fill
            Me.SplitContainer3.Location = New System.Drawing.Point(0, 0)
            Me.SplitContainer3.Name = "SplitContainer3"
            '
            'SplitContainer3.Panel1
            '
            Me.SplitContainer3.Panel1.Controls.Add(Me.GroupBox4)
            '
            'SplitContainer3.Panel2
            '
            Me.SplitContainer3.Panel2.Controls.Add(Me.C1Sizer3)
            Me.SplitContainer3.Size = New System.Drawing.Size(671, 660)
            Me.SplitContainer3.SplitterDistance = 116
            Me.SplitContainer3.TabIndex = 0
            '
            'GroupBox4
            '
            Me.GroupBox4.Controls.Add(Me.C1Sizer2)
            Me.GroupBox4.Dock = System.Windows.Forms.DockStyle.Fill
            Me.GroupBox4.Location = New System.Drawing.Point(0, 0)
            Me.GroupBox4.Name = "GroupBox4"
            Me.GroupBox4.Size = New System.Drawing.Size(116, 660)
            Me.GroupBox4.TabIndex = 0
            Me.GroupBox4.TabStop = False
            Me.GroupBox4.Text = "命令列表"
            '
            'C1Sizer2
            '
            Me.C1Sizer2.Controls.Add(Me.Button19)
            Me.C1Sizer2.Controls.Add(Me.Button18)
            Me.C1Sizer2.Controls.Add(Me.Button17)
            Me.C1Sizer2.Controls.Add(Me.Button16)
            Me.C1Sizer2.Controls.Add(Me.Button15)
            Me.C1Sizer2.Controls.Add(Me.Button14)
            Me.C1Sizer2.Controls.Add(Me.Button13)
            Me.C1Sizer2.Controls.Add(Me.Button12)
            Me.C1Sizer2.Controls.Add(Me.Button11)
            Me.C1Sizer2.Controls.Add(Me.Button10)
            Me.C1Sizer2.Controls.Add(Me.Button9)
            Me.C1Sizer2.Controls.Add(Me.Button8)
            Me.C1Sizer2.Controls.Add(Me.Button7)
            Me.C1Sizer2.Controls.Add(Me.Button6)
            Me.C1Sizer2.Controls.Add(Me.Button5)
            Me.C1Sizer2.Controls.Add(Me.Button4)
            Me.C1Sizer2.Controls.Add(Me.Button3)
            Me.C1Sizer2.Controls.Add(Me.Button2)
            Me.C1Sizer2.Dock = System.Windows.Forms.DockStyle.Fill
            Me.C1Sizer2.GridDefinition = resources.GetString("C1Sizer2.GridDefinition")
            Me.C1Sizer2.ImeMode = System.Windows.Forms.ImeMode.NoControl
            Me.C1Sizer2.Location = New System.Drawing.Point(3, 17)
            Me.C1Sizer2.Name = "C1Sizer2"
            Me.C1Sizer2.Size = New System.Drawing.Size(110, 640)
            Me.C1Sizer2.TabIndex = 0
            Me.C1Sizer2.TabStop = False
            '
            'Button19
            '
            Me.Button19.Location = New System.Drawing.Point(4, 577)
            Me.Button19.Name = "Button19"
            Me.Button19.Size = New System.Drawing.Size(102, 28)
            Me.Button19.TabIndex = 17
            Me.Button19.Text = "Button19"
            Me.Button19.UseVisualStyleBackColor = True
            '
            'Button18
            '
            Me.Button18.Location = New System.Drawing.Point(4, 545)
            Me.Button18.Name = "Button18"
            Me.Button18.Size = New System.Drawing.Size(102, 28)
            Me.Button18.TabIndex = 16
            Me.Button18.Text = "Button18"
            Me.Button18.UseVisualStyleBackColor = True
            '
            'Button17
            '
            Me.Button17.Location = New System.Drawing.Point(4, 512)
            Me.Button17.Name = "Button17"
            Me.Button17.Size = New System.Drawing.Size(102, 29)
            Me.Button17.TabIndex = 15
            Me.Button17.Text = "Button17"
            Me.Button17.UseVisualStyleBackColor = True
            '
            'Button16
            '
            Me.Button16.Location = New System.Drawing.Point(4, 480)
            Me.Button16.Name = "Button16"
            Me.Button16.Size = New System.Drawing.Size(102, 28)
            Me.Button16.TabIndex = 14
            Me.Button16.Text = "Button16"
            Me.Button16.UseVisualStyleBackColor = True
            '
            'Button15
            '
            Me.Button15.Location = New System.Drawing.Point(4, 449)
            Me.Button15.Name = "Button15"
            Me.Button15.Size = New System.Drawing.Size(102, 27)
            Me.Button15.TabIndex = 13
            Me.Button15.Text = "Button15"
            Me.Button15.UseVisualStyleBackColor = True
            '
            'Button14
            '
            Me.Button14.Location = New System.Drawing.Point(4, 417)
            Me.Button14.Name = "Button14"
            Me.Button14.Size = New System.Drawing.Size(102, 28)
            Me.Button14.TabIndex = 12
            Me.Button14.Text = "Button14"
            Me.Button14.UseVisualStyleBackColor = True
            '
            'Button13
            '
            Me.Button13.Location = New System.Drawing.Point(4, 385)
            Me.Button13.Name = "Button13"
            Me.Button13.Size = New System.Drawing.Size(102, 28)
            Me.Button13.TabIndex = 11
            Me.Button13.Text = "Button13"
            Me.Button13.UseVisualStyleBackColor = True
            '
            'Button12
            '
            Me.Button12.Location = New System.Drawing.Point(4, 354)
            Me.Button12.Name = "Button12"
            Me.Button12.Size = New System.Drawing.Size(102, 27)
            Me.Button12.TabIndex = 10
            Me.Button12.Text = "Button12"
            Me.Button12.UseVisualStyleBackColor = True
            '
            'Button11
            '
            Me.Button11.Location = New System.Drawing.Point(4, 321)
            Me.Button11.Name = "Button11"
            Me.Button11.Size = New System.Drawing.Size(102, 29)
            Me.Button11.TabIndex = 9
            Me.Button11.Text = "Button11"
            Me.Button11.UseVisualStyleBackColor = True
            '
            'Button10
            '
            Me.Button10.Location = New System.Drawing.Point(4, 288)
            Me.Button10.Name = "Button10"
            Me.Button10.Size = New System.Drawing.Size(102, 29)
            Me.Button10.TabIndex = 8
            Me.Button10.Text = "Button10"
            Me.Button10.UseVisualStyleBackColor = True
            '
            'Button9
            '
            Me.Button9.Location = New System.Drawing.Point(4, 258)
            Me.Button9.Name = "Button9"
            Me.Button9.Size = New System.Drawing.Size(102, 26)
            Me.Button9.TabIndex = 7
            Me.Button9.Text = "Button9"
            Me.Button9.UseVisualStyleBackColor = True
            '
            'Button8
            '
            Me.Button8.Location = New System.Drawing.Point(4, 225)
            Me.Button8.Name = "Button8"
            Me.Button8.Size = New System.Drawing.Size(102, 29)
            Me.Button8.TabIndex = 6
            Me.Button8.Text = "Button8"
            Me.Button8.UseVisualStyleBackColor = True
            '
            'Button7
            '
            Me.Button7.Location = New System.Drawing.Point(4, 193)
            Me.Button7.Name = "Button7"
            Me.Button7.Size = New System.Drawing.Size(102, 28)
            Me.Button7.TabIndex = 5
            Me.Button7.Text = "Button7"
            Me.Button7.UseVisualStyleBackColor = True
            '
            'Button6
            '
            Me.Button6.Location = New System.Drawing.Point(4, 162)
            Me.Button6.Name = "Button6"
            Me.Button6.Size = New System.Drawing.Size(102, 27)
            Me.Button6.TabIndex = 4
            Me.Button6.Text = "Button6"
            Me.Button6.UseVisualStyleBackColor = True
            '
            'Button5
            '
            Me.Button5.Location = New System.Drawing.Point(4, 130)
            Me.Button5.Name = "Button5"
            Me.Button5.Size = New System.Drawing.Size(102, 28)
            Me.Button5.TabIndex = 3
            Me.Button5.Text = "Button5"
            Me.Button5.UseVisualStyleBackColor = True
            '
            'Button4
            '
            Me.Button4.Location = New System.Drawing.Point(4, 98)
            Me.Button4.Name = "Button4"
            Me.Button4.Size = New System.Drawing.Size(102, 28)
            Me.Button4.TabIndex = 2
            Me.Button4.Text = "Button4"
            Me.Button4.UseVisualStyleBackColor = True
            '
            'Button3
            '
            Me.Button3.Location = New System.Drawing.Point(4, 67)
            Me.Button3.Name = "Button3"
            Me.Button3.Size = New System.Drawing.Size(102, 27)
            Me.Button3.TabIndex = 1
            Me.Button3.Text = "Button3"
            Me.Button3.UseVisualStyleBackColor = True
            '
            'Button2
            '
            Me.Button2.Location = New System.Drawing.Point(4, 35)
            Me.Button2.Name = "Button2"
            Me.Button2.Size = New System.Drawing.Size(102, 28)
            Me.Button2.TabIndex = 0
            Me.Button2.Text = "Button2"
            Me.Button2.UseVisualStyleBackColor = True
            '
            'C1Sizer3
            '
            Me.C1Sizer3.Controls.Add(Me.GroupBox3)
            Me.C1Sizer3.Controls.Add(Me.GroupBox2)
            Me.C1Sizer3.Controls.Add(Me.GroupBox1)
            Me.C1Sizer3.Dock = System.Windows.Forms.DockStyle.Fill
            Me.C1Sizer3.GridDefinition = "32.5757575757576:False:False;32.4242424242424:False:False;32.5757575757576:False:" & _
                "False;" & Global.Microsoft.VisualBasic.ChrW(9) & "98.5480943738657:False:False;"
            Me.C1Sizer3.ImeMode = System.Windows.Forms.ImeMode.NoControl
            Me.C1Sizer3.Location = New System.Drawing.Point(0, 0)
            Me.C1Sizer3.Name = "C1Sizer3"
            Me.C1Sizer3.Size = New System.Drawing.Size(551, 660)
            Me.C1Sizer3.TabIndex = 0
            Me.C1Sizer3.TabStop = False
            '
            'GroupBox3
            '
            Me.GroupBox3.Controls.Add(Me.LVCheck)
            Me.GroupBox3.Location = New System.Drawing.Point(4, 223)
            Me.GroupBox3.Name = "GroupBox3"
            Me.GroupBox3.Size = New System.Drawing.Size(543, 214)
            Me.GroupBox3.TabIndex = 2
            Me.GroupBox3.TabStop = False
            Me.GroupBox3.Text = "审核数据事件列表"
            '
            'LVCheck
            '
            Me.LVCheck.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader4, Me.ColumnHeader5, Me.ColumnHeader6})
            Me.LVCheck.Dock = System.Windows.Forms.DockStyle.Fill
            Me.LVCheck.FullRowSelect = True
            Me.LVCheck.GridLines = True
            Me.LVCheck.HideSelection = False
            Me.LVCheck.Location = New System.Drawing.Point(3, 17)
            Me.LVCheck.Name = "LVCheck"
            Me.LVCheck.Size = New System.Drawing.Size(537, 194)
            Me.LVCheck.TabIndex = 7
            Me.LVCheck.UseCompatibleStateImageBehavior = False
            Me.LVCheck.View = System.Windows.Forms.View.Details
            '
            'ColumnHeader4
            '
            Me.ColumnHeader4.Text = "时间"
            Me.ColumnHeader4.Width = 96
            '
            'ColumnHeader5
            '
            Me.ColumnHeader5.Text = "事件"
            Me.ColumnHeader5.Width = 80
            '
            'ColumnHeader6
            '
            Me.ColumnHeader6.Text = "内容"
            Me.ColumnHeader6.Width = 600
            '
            'GroupBox2
            '
            Me.GroupBox2.Controls.Add(Me.LVSystem)
            Me.GroupBox2.Location = New System.Drawing.Point(4, 441)
            Me.GroupBox2.Name = "GroupBox2"
            Me.GroupBox2.Size = New System.Drawing.Size(543, 215)
            Me.GroupBox2.TabIndex = 1
            Me.GroupBox2.TabStop = False
            Me.GroupBox2.Text = "系统事件列表"
            '
            'LVSystem
            '
            Me.LVSystem.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader7, Me.ColumnHeader8, Me.ColumnHeader9})
            Me.LVSystem.Dock = System.Windows.Forms.DockStyle.Fill
            Me.LVSystem.FullRowSelect = True
            Me.LVSystem.GridLines = True
            Me.LVSystem.HideSelection = False
            Me.LVSystem.Location = New System.Drawing.Point(3, 17)
            Me.LVSystem.Name = "LVSystem"
            Me.LVSystem.Size = New System.Drawing.Size(537, 195)
            Me.LVSystem.TabIndex = 7
            Me.LVSystem.UseCompatibleStateImageBehavior = False
            Me.LVSystem.View = System.Windows.Forms.View.Details
            '
            'ColumnHeader7
            '
            Me.ColumnHeader7.Text = "时间"
            Me.ColumnHeader7.Width = 98
            '
            'ColumnHeader8
            '
            Me.ColumnHeader8.Text = "事件"
            Me.ColumnHeader8.Width = 80
            '
            'ColumnHeader9
            '
            Me.ColumnHeader9.Text = "内容"
            Me.ColumnHeader9.Width = 600
            '
            'GroupBox1
            '
            Me.GroupBox1.Controls.Add(Me.LvMont)
            Me.GroupBox1.Location = New System.Drawing.Point(4, 4)
            Me.GroupBox1.Name = "GroupBox1"
            Me.GroupBox1.Size = New System.Drawing.Size(543, 215)
            Me.GroupBox1.TabIndex = 0
            Me.GroupBox1.TabStop = False
            Me.GroupBox1.Text = "监控点事件列表"
            '
            'LvMont
            '
            Me.LvMont.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3})
            Me.LvMont.Dock = System.Windows.Forms.DockStyle.Fill
            Me.LvMont.FullRowSelect = True
            Me.LvMont.GridLines = True
            Me.LvMont.HideSelection = False
            Me.LvMont.Location = New System.Drawing.Point(3, 17)
            Me.LvMont.Name = "LvMont"
            Me.LvMont.Size = New System.Drawing.Size(537, 195)
            Me.LvMont.TabIndex = 7
            Me.LvMont.UseCompatibleStateImageBehavior = False
            Me.LvMont.View = System.Windows.Forms.View.Details
            '
            'ColumnHeader1
            '
            Me.ColumnHeader1.Text = "时间"
            Me.ColumnHeader1.Width = 98
            '
            'ColumnHeader2
            '
            Me.ColumnHeader2.Text = "事件"
            Me.ColumnHeader2.Width = 80
            '
            'ColumnHeader3
            '
            Me.ColumnHeader3.Text = "内容"
            Me.ColumnHeader3.Width = 600
            '
            'StatusStrip1
            '
            Me.StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripStatusLabel1, Me.La_Time, Me.ToolStripStatusLabel3, Me.la_Data, Me.ToolStripStatusLabel5, Me.la_Enp, Me.ToolStripStatusLabel7, Me.lz_Check})
            Me.StatusStrip1.Location = New System.Drawing.Point(0, 684)
            Me.StatusStrip1.Name = "StatusStrip1"
            Me.StatusStrip1.Size = New System.Drawing.Size(1012, 22)
            Me.StatusStrip1.TabIndex = 2
            Me.StatusStrip1.Text = "StatusStrip1"
            '
            'ToolStripStatusLabel1
            '
            Me.ToolStripStatusLabel1.Name = "ToolStripStatusLabel1"
            Me.ToolStripStatusLabel1.Size = New System.Drawing.Size(65, 17)
            Me.ToolStripStatusLabel1.Text = "运行时间:"
            '
            'La_Time
            '
            Me.La_Time.AutoSize = False
            Me.La_Time.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer))
            Me.La_Time.Name = "La_Time"
            Me.La_Time.Size = New System.Drawing.Size(110, 17)
            '
            'ToolStripStatusLabel3
            '
            Me.ToolStripStatusLabel3.Name = "ToolStripStatusLabel3"
            Me.ToolStripStatusLabel3.Size = New System.Drawing.Size(53, 17)
            Me.ToolStripStatusLabel3.Text = "数据库:"
            '
            'la_Data
            '
            Me.la_Data.ActiveLinkColor = System.Drawing.Color.Red
            Me.la_Data.AutoSize = False
            Me.la_Data.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer))
            Me.la_Data.Name = "la_Data"
            Me.la_Data.Size = New System.Drawing.Size(70, 17)
            '
            'ToolStripStatusLabel5
            '
            Me.ToolStripStatusLabel5.Name = "ToolStripStatusLabel5"
            Me.ToolStripStatusLabel5.Size = New System.Drawing.Size(107, 17)
            Me.ToolStripStatusLabel5.Text = "Socket(监听1):"
            '
            'la_Enp
            '
            Me.la_Enp.AutoSize = False
            Me.la_Enp.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer))
            Me.la_Enp.Name = "la_Enp"
            Me.la_Enp.Size = New System.Drawing.Size(70, 17)
            '
            'ToolStripStatusLabel7
            '
            Me.ToolStripStatusLabel7.Name = "ToolStripStatusLabel7"
            Me.ToolStripStatusLabel7.Size = New System.Drawing.Size(107, 17)
            Me.ToolStripStatusLabel7.Text = "Socket(监听2):"
            '
            'lz_Check
            '
            Me.lz_Check.AutoSize = False
            Me.lz_Check.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer))
            Me.lz_Check.Name = "lz_Check"
            Me.lz_Check.Size = New System.Drawing.Size(70, 17)
            '
            'Timer1
            '
            Me.Timer1.Enabled = True
            Me.Timer1.Interval = 1000
            '
            'frm_Main
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None
            Me.ClientSize = New System.Drawing.Size(1012, 706)
            Me.Controls.Add(Me.SplitContainer1)
            Me.Controls.Add(Me.StatusStrip1)
            Me.Controls.Add(Me.MenuStrip1)
            Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
            Me.MaximizeBox = False
            Me.MinimizeBox = False
            Me.Name = "frm_Main"
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
            Me.Text = "Socket"
            Me.MenuStrip1.ResumeLayout(False)
            Me.MenuStrip1.PerformLayout()
            Me.SplitContainer1.Panel1.ResumeLayout(False)
            Me.SplitContainer1.Panel2.ResumeLayout(False)
            Me.SplitContainer1.ResumeLayout(False)
            Me.GroupBox5.ResumeLayout(False)
            CType(Me.C1Sizer1, System.ComponentModel.ISupportInitialize).EndInit()
            Me.C1Sizer1.ResumeLayout(False)
            Me.SplitContainer3.Panel1.ResumeLayout(False)
            Me.SplitContainer3.Panel2.ResumeLayout(False)
            Me.SplitContainer3.ResumeLayout(False)
            Me.GroupBox4.ResumeLayout(False)
            CType(Me.C1Sizer2, System.ComponentModel.ISupportInitialize).EndInit()
            Me.C1Sizer2.ResumeLayout(False)
            CType(Me.C1Sizer3, System.ComponentModel.ISupportInitialize).EndInit()
            Me.C1Sizer3.ResumeLayout(False)
            Me.GroupBox3.ResumeLayout(False)
            Me.GroupBox2.ResumeLayout(False)
            Me.GroupBox1.ResumeLayout(False)
            Me.StatusStrip1.ResumeLayout(False)
            Me.StatusStrip1.PerformLayout()
            Me.ResumeLayout(False)
            Me.PerformLayout()
    
        End Sub
        Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
        Friend WithEvents 系统ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
        Friend WithEvents 关于ToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
        Friend WithEvents SplitContainer1 As System.Windows.Forms.SplitContainer
        Friend WithEvents StatusStrip1 As System.Windows.Forms.StatusStrip
        Friend WithEvents ToolStripStatusLabel1 As System.Windows.Forms.ToolStripStatusLabel
        Friend WithEvents La_Time As System.Windows.Forms.ToolStripStatusLabel
        Friend WithEvents ToolStripStatusLabel3 As System.Windows.Forms.ToolStripStatusLabel
        Friend WithEvents la_Data As System.Windows.Forms.ToolStripStatusLabel
        Friend WithEvents ToolStripStatusLabel5 As System.Windows.Forms.ToolStripStatusLabel
        Friend WithEvents la_Enp As System.Windows.Forms.ToolStripStatusLabel
        Friend WithEvents SplitContainer3 As System.Windows.Forms.SplitContainer
        Friend WithEvents C1Sizer3 As C1.Win.C1Sizer.C1Sizer
        Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
        Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
        Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
        Friend WithEvents ToolStripStatusLabel7 As System.Windows.Forms.ToolStripStatusLabel
        Friend WithEvents lz_Check As System.Windows.Forms.ToolStripStatusLabel
        Friend WithEvents GroupBox5 As System.Windows.Forms.GroupBox
        Friend WithEvents C1Sizer1 As C1.Win.C1Sizer.C1Sizer
        Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
        Friend WithEvents Button1 As System.Windows.Forms.Button
        Friend WithEvents C1Sizer2 As C1.Win.C1Sizer.C1Sizer
        Friend WithEvents Button19 As System.Windows.Forms.Button
        Friend WithEvents Button18 As System.Windows.Forms.Button
        Friend WithEvents Button17 As System.Windows.Forms.Button
        Friend WithEvents Button16 As System.Windows.Forms.Button
        Friend WithEvents Button15 As System.Windows.Forms.Button
        Friend WithEvents Button14 As System.Windows.Forms.Button
        Friend WithEvents Button13 As System.Windows.Forms.Button
        Friend WithEvents Button12 As System.Windows.Forms.Button
        Friend WithEvents Button11 As System.Windows.Forms.Button
        Friend WithEvents Button10 As System.Windows.Forms.Button
        Friend WithEvents Button9 As System.Windows.Forms.Button
        Friend WithEvents Button8 As System.Windows.Forms.Button
        Friend WithEvents Button7 As System.Windows.Forms.Button
        Friend WithEvents Button6 As System.Windows.Forms.Button
        Friend WithEvents Button5 As System.Windows.Forms.Button
        Friend WithEvents Button4 As System.Windows.Forms.Button
        Friend WithEvents Button3 As System.Windows.Forms.Button
        Friend WithEvents Button2 As System.Windows.Forms.Button
        Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
        Friend WithEvents LVCheck As System.Windows.Forms.ListView
        Friend WithEvents ColumnHeader4 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader5 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader6 As System.Windows.Forms.ColumnHeader
        Friend WithEvents LVSystem As System.Windows.Forms.ListView
        Friend WithEvents ColumnHeader7 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader8 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader9 As System.Windows.Forms.ColumnHeader
        Friend WithEvents LvMont As System.Windows.Forms.ListView
        Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
        Friend WithEvents Timer1 As System.Windows.Forms.Timer
    End Class
    
    2009年8月20日 3:28
  • 请用异步方式accept
    参考http://www.cnblogs.com/waynebaby/archive/2009/01/14/1375234.html

    答案破千 马上就要到5星用户了 嘿嘿~~
    2009年8月20日 9:17