c# - Calling EventHandlers for static method -
i have 1 class has 2 static methods a() , b().
here a() methods needs subscribe 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 class not working static methods when controls pass static method dont pass through constructor.
here want 2 things :
- how set eventhandler in class saved static methods?
- how subscribe , unsubscribe them can't overlap?
you can try doing want in static constructor.
public class myclass { static myclass() { // todo : attach static event handlers here } }
please note can use static properties, fields, events, etc in here. if object singleton, there other implications , should read jon skeet's article on singleton implementation in c# full view of things.
Comments
Post a Comment