internal EventNotify(ISpEventSource sapiEventSource, IAsyncDispatch dispatcher, bool additionalSapiFeatures) { _sapiEventSourceReference = new WeakReference(sapiEventSource); _dispatcher = dispatcher; _additionalSapiFeatures = additionalSapiFeatures; _notifySink = new SpNotifySink(this); sapiEventSource.SetNotifySink(_notifySink); }
internal EventNotify(ISpEventSource sapiEventSource, IAsyncDispatch dispatcher, bool additionalSapiFeatures) { // Remember event source _sapiEventSourceReference = new WeakReference(sapiEventSource); _dispatcher = dispatcher; _additionalSapiFeatures = additionalSapiFeatures; // Start listening to events from sapiEventSource. _notifySink = new SpNotifySink(this); sapiEventSource.SetNotifySink(_notifySink); }
internal void Dispose() { lock (this) { if (_sapiEventSourceReference != null) { ISpEventSource spEventSource = (ISpEventSource)_sapiEventSourceReference.Target; if (spEventSource != null) { spEventSource.SetNotifySink(null); _notifySink = null; } } _sapiEventSourceReference = null; } }
// Finalizer is not required since ISpEventSource and AsyncOperation both implement appropriate finalizers. internal void Dispose() { lock (this) { // Since we are explicitly calling Dispose(), sapiEventSource (RCW) will normally be alive. // If Dispose() is called from a finalizer this may not be the case so check for null. if (_sapiEventSourceReference != null) { ISpEventSource sapiEventSource = (ISpEventSource)_sapiEventSourceReference.Target; if (sapiEventSource != null) { // Stop listening to events from sapiEventSource. sapiEventSource.SetNotifySink(null); _notifySink = null; } } _sapiEventSourceReference = null; } }