locked
Calling EventHandlers for static method RRS feed

  • Question

  • User-1547279409 posted
    I have one class it has two static methods A() and B() Here A() methods needs to subscribe some events like: push.Events.OnDeviceSubscriptionExpired += new PushSharp.Common.ChannelEvents.DeviceSubscriptionExpired(Events_OnDeviceSubscriptionExpired); push.Events.OnDeviceSubscriptionIdChanged += new PushSharp.Common.ChannelEvents.DeviceSubscriptionIdChanged(Events_OnDeviceSubscriptionIdChanged); I kept them in constructor of the class but it is not working for static methods Actually when controls pass to static method it dont pass through constructor Here I want two things 1. How to set eventhandler in class so that it could be saved by static methods 2. How to subscribe and unsubscribe them so that they can't overlap
    Friday, April 5, 2013 4:53 AM

Answers

  • User-1241139641 posted

    Is the constructor your assigning the events to also static? Static constructor will be called once so you can init any code that will be needed by your static methods.

    class MyClass
    {
    static MyClass() {
    //code here
     }
    }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 5, 2013 8:11 AM