Esempio n. 1
0
        protected virtual void UnregisterInstance()
        {
            lock (_GlobalLock)
            {
                GlobalInstances.Remove(Serial);
            }

            var user = User;

            if (user == null)
            {
                lock (_InstanceLock)
                {
                    user = Instances.FirstOrDefault(kv => kv.Value.Contains(this)).Key;
                }
            }

            if (user == null)
            {
                return;
            }

            List <SuperGump> list;

            lock (_InstanceLock)
            {
                list = Instances.GetValue(User);

                if (list == null || list.Count == 0)
                {
                    Instances.Remove(user);
                    return;
                }
            }

            var removed = false;

            lock (((ICollection)list).SyncRoot)
            {
                if (list.Remove(this))
                {
                    list.TrimExcess();

                    removed = true;
                }

                if (list.Count == 0)
                {
                    lock (_InstanceLock)
                    {
                        Instances.Remove(user);
                    }
                }
            }

            if (removed)
            {
                OnInstanceUnregistered();
            }
        }
Esempio n. 2
0
        protected virtual void UnregisterInstance()
        {
            lock (GlobalInstances)
            {
                GlobalInstances.Remove(Serial);
            }

            bool removed = false;

            lock (Instances)
            {
                PlayerMobile user = User ?? Instances.FirstOrDefault(kv => kv.Value.Contains(this)).Key;

                if (user == null)
                {
                    return;
                }

                List <SuperGump> list;

                if (!Instances.TryGetValue(user, out list))
                {
                    return;
                }

                if (list == null)
                {
                    Instances.Remove(user);
                    return;
                }

                if (list.Remove(this))
                {
                    removed = true;
                }

                if (list.Count == 0)
                {
                    Instances.Remove(user);
                }
            }

            if (removed)
            {
                OnInstanceUnregistered();
            }
        }