c# - How to deregister correctly from receiving notifications using IConnectPoint Unadvise? -
in documentation mobile broadband api, says:
the following procedure describes how register notifications.
1.get iconnectionpointcontainer interface calling queryinterface on imbninterfacemanager > object.
2.call findconnectionpoint on returned interface , pass iid_imbnpinevents riid.
3.call advise on returned connection point , pass pointer iunknown interface on > object implements imbnpinevents punk.notifications can terminated calling unadvise on connection point returned in step 2.
i have got code carries out first 3 steps, , registers mbn events. however, need de-register temporarily receiving these events.
so, after couple of first attempts ended com exceptions, tried following code (with try/catch blocks):
//first notifications public void registerevent(object iunk, guid guid, out uint storedtag) { iconnectionpoint icp = null; guid curguid = guid; storedtag = 0; if ((curguid == typeof(imbninterfacemanagerevents).guid) ) { // event, connection point defined on interface manager object m_interfacemanagercpc.findconnectionpoint(ref curguid, out icp); // call advise on connection point register icp.advise(iunk, out storedtag); //save iconnectionpoint object interfacemanagercp = icp; } //now deregister events public void deregisterevent(guid guid, uint storedtag) { iconnectionpoint icp = null; guid curguid = guid; // find appropriate connection point call unadvise on if ((curguid == typeof(imbninterfacemanagerevents).guid) ) { // call unadvise on saved connection point de-register interfacemanagercp.unadvise(storedtag); }
when run code, no errors or exceptions mbn. event handlers aren't de-registered. can still see in log files, mbn events arriving , being handled.
can tell me missing? thank you.
i think figured out problem. have many different types of guids, , thought used same iconnectionpoint, saved same object in registerevent function.
when tried creating new iconnectionpoint object each guid, , saving each iconnectionpoint separately, deregisterevent function worked properly.
Comments
Post a Comment