File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,8 +34,6 @@ public ObjectPoolAutoTrimmer(
3434 TimeSpan ? trimDelay = null )
3535 {
3636 _pool = pool ?? throw new ArgumentNullException ( "pool" ) ;
37- if ( pool is DisposableBase d )
38- d . BeforeDispose += Pool_BeforeDispose ;
3937
4038 TrimmedSize = _trimmedSize = trimmedSize ;
4139 TrimDelay = _trimDelay = trimDelay ?? TimeSpan . FromMilliseconds ( 500 ) ;
@@ -45,6 +43,11 @@ public ObjectPoolAutoTrimmer(
4543 pool . GivenTo += Target_GivenTo ;
4644 pool . TakenFrom += Target_TakenFrom ;
4745
46+ if ( pool is DisposableBase d )
47+ {
48+ if ( d . IsDisposed ) throw new ArgumentException ( "Cannot trim for an object pool that is already disposed." ) ;
49+ d . BeforeDispose += Pool_BeforeDispose ;
50+ }
4851 }
4952
5053 protected virtual void Target_GivenTo ( int newSize )
Original file line number Diff line number Diff line change @@ -32,7 +32,11 @@ public Recycler(
3232 } ) ;
3333
3434 if ( target is DisposableBase d )
35+ {
36+ if ( d . IsDisposed ) throw new ArgumentException ( "Cannot recycle for an object pool that is already disposed." ) ;
3537 d . BeforeDispose += Pool_BeforeDispose ;
38+ // Could possibly dispose before this line somewhere... But that's just nasty. :P
39+ }
3640 }
3741
3842 public Recycler (
You can’t perform that action at this time.
0 commit comments