简体   繁体   English

事件vb.net,有什么用?

[英]Event vb.net, how useful?

I've been searching for hour on how to create event with vb.net, but all tutorial seem pointless since they use event who already exist. 我一直在寻找有关如何使用vb.net创建事件的时间,但是所有教程似乎毫无意义,因为它们使用了已经存在的事件。 Basically I don't get it. 基本上我不明白。

So what I would like to raise a custom event so imagine a user connect it's detected here 所以我想引发一个自定义事件,以便想象在这里检测到用户连接

Private Sub AcceptClient(ByVal iAr As IAsyncResult)
    Try
        Dim _listener As TcpListener = CType(iAr.AsyncState, TcpListener)
        Dim _client As TcpClient = _listener.EndAcceptTcpClient(iAr)

        'Here would be an event who's raised but I really don't know how'

        _client.GetStream.BeginRead(receiveByte, 0, 4096, AddressOf Receiving, _client)

        _listener.BeginAcceptTcpClient(New AsyncCallback(AddressOf AcceptClient), _listener)
    Catch ex As Exception
        Return
    End Try
End Sub

So what would I like to do with the event don't really matter, but I don't know how to create my own event. 因此,我对事件的处理并不重要,但是我不知道如何创建自己的事件。

Also could someone explain the difference between calling a function where the comment is and raising an event. 也有人可以解释调用注释所在的函数与引发事件之间的区别。

Thank you 谢谢

Check out this link it shows how to create and handle and event http://msdn.microsoft.com/en-us/library/ms973905.aspx 查看此链接,它显示了如何创建和处理事件http://msdn.microsoft.com/zh-cn/library/ms973905.aspx

Your question about raising an event vs calling a method Raising events vs direct method calls differences 关于引发事件与调用方法的问题引发事件与直接方法的问题称为差异

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM