/// <summary> /// 当有拦截器失效时 /// </summary> /// <param name="interceptor">拦截器</param> private void OnInterceptorDeactivate(LifetimeInterceptor interceptor) { // 切换激活状态的记录的实例 this.lifeTimeInterceptorLazy = new Lazy <LifetimeInterceptor>( this.CreateInterceptor, LazyThreadSafetyMode.ExecutionAndPublication); this.interceptorCleaner.Add(interceptor); }
/// <summary> /// 添加要清除的拦截器 /// </summary> /// <param name="interceptor">拦截器</param> public void Add(LifetimeInterceptor interceptor) { var entry = new TrackingEntry(interceptor); this.trackingEntries.Enqueue(entry); // 从0变为1,要启动清理作业 if (Interlocked.Increment(ref this.trackingEntryCount) == 1) { this.StartCleanup(); } }
/// <summary> /// 监视生命周期的记录 /// </summary> /// <param name="interceptor">激活状态的拦截器</param> public TrackingEntry(LifetimeInterceptor interceptor) { this.disposable = interceptor.HttpApiConfig; this.weakReference = new WeakReference(interceptor); }