// Token: 0x0600768D RID: 30349 RVA: 0x0018686C File Offset: 0x00184A6C
        private void HandleMonitorRemove(ResourceKey key, CacheableResourceHealthMonitor value, RemoveReason reason)
        {
            ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceKey, RemoveReason>((long)this.GetHashCode(), "[ResourceHealthMonitorManager.HandleMonitorRemove] Removing monitor {0} due to reason {1}", key, reason);
            if (!value.Expired)
            {
                value.Expire();
            }
            IDisposable disposable = value as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
        }
        // Token: 0x0600768A RID: 30346 RVA: 0x001865DC File Offset: 0x001847DC
        private bool HandleResourceCacheShouldRemove(ResourceKey key, CacheableResourceHealthMonitor monitor)
        {
            bool flag = false;
            bool result;

            try
            {
                if (monitor is IResourceHealthPoller)
                {
                    if (!Monitor.TryEnter(monitor, 0))
                    {
                        ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[ResourceHealthMonitorManager.HandleResourceCacheShouldRemove] Could not grab the monitor - extending life in cache for key: {0}", key);
                        return(false);
                    }
                    flag = true;
                }
                bool flag2 = true;
                if (monitor != null)
                {
                    flag2 = (DateTime.UtcNow - monitor.LastAccessUtc > ResourceHealthMonitorManager.MonitorSlidingExpiration && monitor.ShouldRemoveResourceFromCache());
                }
                if (flag2)
                {
                    this.pollingMonitors.Remove(key);
                    monitor.Expire();
                }
                result = flag2;
            }
            finally
            {
                if (flag)
                {
                    Monitor.Exit(monitor);
                }
            }
            return(result);
        }
        // Token: 0x06007686 RID: 30342 RVA: 0x00186284 File Offset: 0x00184484
        public IResourceLoadMonitor Get(ResourceKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            CacheableResourceHealthMonitor cacheableResourceHealthMonitor = null;

            if (!this.monitors.TryGetValue(key, out cacheableResourceHealthMonitor))
            {
                bool flag  = false;
                bool flag2 = false;
                bool flag3 = true;
                CacheableResourceHealthMonitor cacheableResourceHealthMonitor2 = null;
                try
                {
                    if (ResourceHealthMonitorManager.Active && ExTraceGlobals.ResourceHealthManagerTracer.IsTraceEnabled(TraceType.DebugTrace))
                    {
                        StackTrace arg = new StackTrace();
                        ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceHealthComponent, ResourceKey, StackTrace>((long)this.GetHashCode(), "[ResourceHealthMonitorManager.Get] Creating new monitor for component '{0}'.  Resource Identity: {1}, Stack Trace: {2}", ResourceHealthMonitorManager.resourceHealthComponent, key, arg);
                    }
                    cacheableResourceHealthMonitor2 = ((ResourceHealthMonitorManager.Active && key.MetricType != ResourceMetricType.None) ? key.CreateMonitor() : new DummyResourceHealthMonitor(key));
                    lock (this.instanceLock)
                    {
                        if (!this.monitors.TryGetValue(key, out cacheableResourceHealthMonitor))
                        {
                            flag3 = false;
                            flag2 = true;
                            if (cacheableResourceHealthMonitor2 is DummyResourceHealthMonitor)
                            {
                                ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[ResourceHealthMonitorManager.Get] Dummy monitor created for resource key {0}", key);
                                this.monitors.TryAddAbsolute(key, cacheableResourceHealthMonitor2, ResourceHealthMonitorManager.DummyMonitorAbsoluteExpiration);
                            }
                            else
                            {
                                this.monitors.TryAddAbsolute(key, cacheableResourceHealthMonitor2, ResourceHealthMonitorManager.MonitorSlidingExpiration);
                            }
                            cacheableResourceHealthMonitor = cacheableResourceHealthMonitor2;
                            flag = true;
                        }
                    }
                }
                finally
                {
                    if (flag3 && cacheableResourceHealthMonitor2 != null)
                    {
                        cacheableResourceHealthMonitor2.Expire();
                        IDisposable disposable = cacheableResourceHealthMonitor2 as IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                        cacheableResourceHealthMonitor2 = null;
                    }
                }
                if (flag2)
                {
                    ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[ResourceHealthMonitorManager::Get] Cache miss for key '{0}'", key);
                }
                if (flag)
                {
                    IResourceHealthPoller pollHealth = cacheableResourceHealthMonitor as IResourceHealthPoller;
                    if (pollHealth != null)
                    {
                        using (ActivityContext.SuppressThreadScope())
                        {
                            ThreadPool.QueueUserWorkItem(delegate(object state)
                            {
                                this.HandlePollingItemShouldRemove(key, pollHealth);
                            });
                        }
                        ExTraceGlobals.ClientThrottlingTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[ResourceHealthMonitorManager::Get] Adding monitor as polling monitor: {0}", key);
                        this.pollingMonitors.TryAddAbsolute(key, pollHealth, pollHealth.Interval);
                    }
                }
            }
            return(cacheableResourceHealthMonitor.CreateWrapper());
        }