예제 #1
0
        private void CleanupObjectCache()
        {
            lock (this)
            {
                List <ulong> diposedKeys = new List <ulong>();

                // Find any Disposed Values
                foreach (KeyValuePair <ulong, WeakReference <IObject> > kvp in this.CachedObjects)
                {
                    IObject target;
                    if (!kvp.Value.TryGetTarget(out target))
                    {
                        diposedKeys.Add(kvp.Key);
                    }
                }
                // Now safely remove from the Dictionary
                foreach (ulong key in diposedKeys)
                {
                    this.CachedObjects.Remove(key);
                    if (LoggerAdapter.IsAvailable() &&
                        LoggerAdapter.FoundationInstance.Interface != IntPtr.Zero &&
                        LoggerAdapter.FoundationInstance.GetCategoryLevel(null) >= LoggerLevel.Debug)
                    {
                        LoggerAdapter.LogMessage(LoggerLevel.Debug, 2, "RemoveFromCache", new PropertyValueAdapter(key));
                    }
                }
            }
        }
예제 #2
0
        private void AddToCache(ulong uniqueId, IObject instance)
        {
            this.CachedObjects[uniqueId] = new WeakReference <IObject>(instance);

            if (LoggerAdapter.IsAvailable() &&
                LoggerAdapter.FoundationInstance.GetCategoryLevel(null) >= LoggerLevel.Debug)
            {
                string   typeName    = instance.GetType().ToString();
                IntPtr[] pParameters = new IntPtr[2];
                pParameters[0] = new PropertyValueAdapter(uniqueId).Detach();
                pParameters[1] = new PropertyValueAdapter(typeName).Detach();
                LoggerAdapter.LogMessage(LoggerLevel.Debug, 1, "AddToCache", new PropertyValueAdapter(pParameters));
            }
        }