How can I use the following events/delegates, written in C#, in VB.NET?

后端 未结 3 1081
面向向阳花
面向向阳花 2021-01-24 21:44

I\'m using JdSoft\'s APNS-Sharp library in my ASP.NET web app. The library is written in C#, and makes extensive use of Delegate Functions and Events for threading purposes. My

相关标签:
3条回答
  • 2021-01-24 22:17

    I'm not sure on the VB implementation I'm afraid, but the += syntax in C# with respect to delegates, adds a method to the delegates list of methods (invocation list)

    0 讨论(0)
  • 2021-01-24 22:20

    The += operator is basically subscribing the FeedbackService.OnError function to the Error invocation list. So when the Error event is raised, the OnError method is invoked.

    To translate the above code to VB.NET, it would look something like:

    // define delelgate/event
    Public Delegate Sub OnError(sender As Object, ex As Exception)
    Public Event OnError Error
    
    // attach method to event
    AddHandler service.Error, service_Error
    

    See How to: Raise and Consume Events for some examples in VB.NET.

    0 讨论(0)
  • 2021-01-24 22:35
    AddHandler service.Error, service_Error
    
    0 讨论(0)
提交回复
热议问题