private void NotifyCreatingInstance() { lock (_instances) { _instances.Add(Id, this); } InstancesChanged?.Invoke(null, ActivitiesCollectionChangedEventArgs.Added(Id, Instances)); }
private void NotifyCreatingInstance() { IImmutableDictionary <int, BaseActivity> capture, updated; do { capture = _instances; updated = capture.Add(Id, this); } while (Interlocked.CompareExchange(ref _instances, updated, capture) != capture); InstancesChanged?.Invoke(null, ActivitiesCollectionChangedEventArgs.Added(Id, updated)); }