@@ -38,9 +38,6 @@ public class MemoryCache : ObjectCache, IEnumerable, IDisposable
38
38
private readonly bool _configLess ;
39
39
private bool _useMemoryCacheManager = true ;
40
40
private bool _throwOnDisposed ;
41
- private EventHandler _onAppDomainUnload ;
42
- private UnhandledExceptionEventHandler _onUnhandledException ;
43
- private int _inUnhandledExceptionHandler ;
44
41
#if NET
45
42
[ UnsupportedOSPlatformGuard ( "browser" ) ]
46
43
private static bool _countersSupported => ! OperatingSystem . IsBrowser ( ) ;
@@ -216,13 +213,6 @@ private void InitDisposableMembers(NameValueCollection config)
216
213
_storeRefs [ i ] = new GCHandleRef < MemoryCacheStore > ( new MemoryCacheStore ( this , _perfCounters ) ) ;
217
214
}
218
215
_stats = new MemoryCacheStatistics ( this , config ) ;
219
- AppDomain appDomain = Thread . GetDomain ( ) ;
220
- EventHandler onAppDomainUnload = new EventHandler ( OnAppDomainUnload ) ;
221
- appDomain . DomainUnload += onAppDomainUnload ;
222
- _onAppDomainUnload = onAppDomainUnload ;
223
- UnhandledExceptionEventHandler onUnhandledException = new UnhandledExceptionEventHandler ( OnUnhandledException ) ;
224
- appDomain . UnhandledException += onUnhandledException ;
225
- _onUnhandledException = onUnhandledException ;
226
216
dispose = false ;
227
217
}
228
218
finally
@@ -234,26 +224,6 @@ private void InitDisposableMembers(NameValueCollection config)
234
224
}
235
225
}
236
226
237
- private void OnAppDomainUnload ( object unusedObject , EventArgs unusedEventArgs )
238
- {
239
- Dispose ( ) ;
240
- }
241
-
242
- internal bool InUnhandledExceptionHandler => _inUnhandledExceptionHandler > 0 ;
243
- private void OnUnhandledException ( object sender , UnhandledExceptionEventArgs eventArgs )
244
- {
245
- Interlocked . Increment ( ref _inUnhandledExceptionHandler ) ;
246
-
247
- // if the CLR is terminating, dispose the cache.
248
- // This will dispose the perf counters
249
- if ( eventArgs . IsTerminating )
250
- {
251
- Dispose ( ) ;
252
- }
253
-
254
- Interlocked . Decrement ( ref _inUnhandledExceptionHandler ) ;
255
- }
256
-
257
227
private static void ValidatePolicy ( CacheItemPolicy policy )
258
228
{
259
229
if ( policy . AbsoluteExpiration != ObjectCache . InfiniteAbsoluteExpiration
@@ -477,8 +447,6 @@ public void Dispose()
477
447
{
478
448
if ( Interlocked . Exchange ( ref _disposed , 1 ) == 0 )
479
449
{
480
- // unhook domain events
481
- DisposeSafeCritical ( ) ;
482
450
// stats must be disposed prior to disposing the stores.
483
451
_stats ? . Dispose ( ) ;
484
452
if ( _storeRefs != null )
@@ -499,19 +467,6 @@ public void Dispose()
499
467
}
500
468
}
501
469
502
- private void DisposeSafeCritical ( )
503
- {
504
- AppDomain appDomain = Thread . GetDomain ( ) ;
505
- if ( _onAppDomainUnload != null )
506
- {
507
- appDomain . DomainUnload -= _onAppDomainUnload ;
508
- }
509
- if ( _onUnhandledException != null )
510
- {
511
- appDomain . UnhandledException -= _onUnhandledException ;
512
- }
513
- }
514
-
515
470
private object GetInternal ( string key , string regionName )
516
471
{
517
472
if ( regionName != null )
0 commit comments