11/*!
22 * @author electricessence / https://github.com/electricessence/
3- * Licensing: MIThttps ://github.com/electricessence /Open.Disposable/blob/master/LISCENSE .md
3+ * Licensing: MIT https ://github.com/Open-NET-Libraries /Open.Disposable/blob/master/LICENSE .md
44 */
55
66using System ;
@@ -100,7 +100,9 @@ public void SetCleanup(CleanupMode mode = CleanupMode.Deferred)
100100 // No past due action in order to prevent another thread from firing...
101101 LastCleanup = DateTime . MaxValue ;
102102 DeferCleanup ( ) ;
103- Task . Factory . StartNew ( ( ) => Cleanup ( ) ) ;
103+ #pragma warning disable CA2008 // Last cleanup value protects against repeat task creation.
104+ Task . Factory . StartNew ( Cleanup ) ;
105+ #pragma warning restore CA2008
104106 }
105107 }
106108 break ;
@@ -119,7 +121,7 @@ public void DeferCleanup()
119121 if ( WasDisposed ) return ;
120122 IsRunning = true ;
121123
122- if ( _cleanupTimer == null )
124+ if ( _cleanupTimer is null )
123125 _cleanupTimer = new Timer ( Cleanup , null , _cleanupDelay , Timeout . Infinite ) ;
124126 else
125127 _cleanupTimer . Change ( _cleanupDelay , Timeout . Infinite ) ;
@@ -138,7 +140,8 @@ public void ClearCleanup()
138140 }
139141 }
140142
141- private void Cleanup ( object ? state = null )
143+ private void Cleanup ( ) => Cleanup ( null ) ;
144+ private void Cleanup ( object ? state )
142145 {
143146 if ( WasDisposed )
144147 return ; // If another thread enters here after disposal don't allow.
@@ -147,10 +150,12 @@ private void Cleanup(object? state = null)
147150 {
148151 OnCleanup ( ) ;
149152 }
153+ #pragma warning disable CA1031 // Do not catch general exception types
150154 catch ( Exception ex )
151155 {
152156 Debug . WriteLine ( ex . ToString ( ) ) ;
153157 }
158+ #pragma warning restore CA1031 // Do not catch general exception types
154159
155160 lock ( _timerSync )
156161 {
0 commit comments