private void NotifyDestroyingInstance(bool isFinalizer) { try { lock (_instances) { _instances.Remove(Id); } DispatchedHandler notify = () => { try { InstancesChanged?.Invoke(null, ActivitiesCollectionChangedEventArgs.Removed(Id, Instances)); } catch (Exception e) { this.Log().Error("An exception was thrown while notifying instance collection changed.", e); } }; if (isFinalizer) { CoreDispatcher.Main.RunAsync(CoreDispatcherPriority.Normal, notify); } else { notify(); } } catch (Exception e) { this.Log().Error("Failed to remove activity from instances collection.", e); } }
private void NotifyDestroyingInstance(bool isFinalizer) { try { IImmutableDictionary <int, BaseActivity> capture, updated; do { capture = _instances; if (!capture.ContainsKey(Id)) { return; } updated = capture.Remove(Id); } while (Interlocked.CompareExchange(ref _instances, updated, capture) != capture); DispatchedHandler notify = () => { try { InstancesChanged?.Invoke(null, ActivitiesCollectionChangedEventArgs.Removed(Id, updated)); } catch (Exception e) { this.Log().Error("An exception was thrown while notifying instance collection changed.", e); } }; if (isFinalizer) { CoreDispatcher.Main.RunAsync(CoreDispatcherPriority.Normal, notify); } else { notify(); } } catch (Exception e) { this.Log().Error("Failed to remove activity from instances collection.", e); } }