internal override void StartHandlerEntryTimer(ActiveHandlerTrackingEntry entry) { if (EnableExpiryTimer) { lock (ActiveEntryState) { if (ActiveEntryState.ContainsKey(entry)) { // Timer already started. return; } // Rather than using the actual timer on the actual entry, let's fake it with async. var completionSource = new TaskCompletionSource <ActiveHandlerTrackingEntry>(); var expiryTask = completionSource.Task.ContinueWith(t => { var e = t.Result; ExpiryTimer_Tick(e); lock (ActiveEntryState) { ActiveEntryState.Remove(e); } }); ActiveEntryState.Add(entry, (completionSource, expiryTask)); } } }
public ExpiredHandlerTrackingEntry(ActiveHandlerTrackingEntry other) { Name = other.Name; _livenessTracker = new WeakReference(other.Handler); InnerHandler = other.Handler.InnerHandler; }
public HttpMessageHandler CreateHandler(string name) { ThrowHelper.ThrowIfNull(name); ActiveHandlerTrackingEntry entry = _activeHandlers.GetOrAdd(name, _entryFactory).Value; StartHandlerEntryTimer(entry); return(entry.Handler); }
public HttpMessageHandler CreateHandler(string name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } ActiveHandlerTrackingEntry entry = _activeHandlers.GetOrAdd(name, _entryFactory).Value; StartHandlerEntryTimer(entry); return(entry.Handler); }
// Internal so it can be overridden in tests internal virtual void StartHandlerEntryTimer(ActiveHandlerTrackingEntry entry) { entry.StartExpiryTimer(_expiryCallback); }