File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -163,17 +163,20 @@ public void StartMonitoringNetworkChanges()
163163
164164 // Monitor network changes to invalidate Alt-Svc headers.
165165 // A weak reference is used to avoid NetworkChange.NetworkAddressChanged keeping a non-disposed connection pool alive.
166- var poolsRef = new WeakReference < ConcurrentDictionary < HttpConnectionKey , HttpConnectionPool > > ( _pools ) ;
167- NetworkAddressChangedEventHandler networkChangedDelegate = delegate
168- {
169- if ( poolsRef . TryGetTarget ( out ConcurrentDictionary < HttpConnectionKey , HttpConnectionPool > ? pools ) )
166+ NetworkAddressChangedEventHandler networkChangedDelegate ;
167+ { // scope to avoid closure if _networkChangeCleanup != null
168+ var poolsRef = new WeakReference < ConcurrentDictionary < HttpConnectionKey , HttpConnectionPool > > ( _pools ) ;
169+ networkChangedDelegate = delegate
170170 {
171- foreach ( HttpConnectionPool pool in pools . Values )
171+ if ( poolsRef . TryGetTarget ( out ConcurrentDictionary < HttpConnectionKey , HttpConnectionPool > ? pools ) )
172172 {
173- pool . OnNetworkChanged ( ) ;
173+ foreach ( HttpConnectionPool pool in pools . Values )
174+ {
175+ pool . OnNetworkChanged ( ) ;
176+ }
174177 }
175- }
176- } ;
178+ } ;
179+ }
177180
178181 var cleanup = new NetworkChangeCleanup ( networkChangedDelegate ) ;
179182
You can’t perform that action at this time.
0 commit comments