internal void Unadvise() { if (isAdvised) { connectionPoint.Unadvise(cookie); } isAdvised = false; }
private void DisposeAll() { if (_connectionPoint == null) { return; } if (_adviseCookie == -1) { return; } try { _connectionPoint.Unadvise(_adviseCookie); // _connectionPoint has entered the CLR in the constructor // for this object and hence its ref counter has been increased // by us. We have not exposed it to other components and // hence it is safe to call RCO on it w/o worrying about // killing the RCW for other objects that link to it. Marshal.ReleaseComObject(_connectionPoint); } catch (Exception ex) { // if something has gone wrong, and the object is no longer attached to the CLR, // the Unadvise is going to throw. In this case, since we're going away anyway, // we'll ignore the failure and quietly go on our merry way. COMException exCOM = ex as COMException; if (exCOM != null && exCOM.ErrorCode == ComHresults.CONNECT_E_NOCONNECTION) { Debug.Assert(false, "IConnectionPoint::Unadvise returned CONNECT_E_NOCONNECTION."); throw; } } finally { _connectionPoint = null; _adviseCookie = -1; _sourceIid = Guid.Empty; } }
public void Disconnect() { try { if (_connectionPoint == null) { return; } if (_cookie.HasValue) { // TODO: Fix: hangs when disposing. _connectionPoint.Unadvise(_cookie.Value); _cookie = null; } Marshal.ReleaseComObject(_connectionPoint); _connectionPoint = null; } catch (Exception ex) { Log.Error("Failed to unsubscribe callback.", ex); } }