none
請問vb.net是否有 vb6 的datarrival 的 event 可以使用 謝謝 RRS feed

解答

  • 沒有,但是你可以寫個自訂類別來包出這個事件,我是這麼包:

    Public Event DataArrival(ByVal sender As Socket)
    Private Sub ReceiveCallback(ByVal result As IAsyncResult) Dim connection As AsyncConnectionInfo = result.AsyncState Try Dim num_read As Int32 = connection.socket.EndReceive(result) If 0 <> num_read Then Description = String.Format("Receive {0} bytes:{1}", num_read, connection.socket.RemoteEndPoint.ToString) RaiseEvent DataArrival(connection.socket) connection.socket.BeginReceive(connection.buffer, 0, BufferSize - 1, SocketFlags.Peek, New AsyncCallback(AddressOf ReceiveCallback), connection) Else closeSocket(connection) End If Catch socketException As SocketException If socketException.ErrorCode = 10054 Then closeSocket(connection) End If Catch exception As ObjectDisposedException closeSocket(connection) End Try End Sub

    T.L. Cheng
    2009年10月10日 上午 03:24
    版主