Пример #1
0
        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);
            }
        }
Пример #2
0
        private void NotifyCreatingInstance()
        {
            lock (_instances)
            {
                _instances.Add(Id, this);
            }

            InstancesChanged?.Invoke(null, ActivitiesCollectionChangedEventArgs.Added(Id, Instances));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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);
            }
        }