@@ -168,31 +168,34 @@ private Task HandleReactionClear(DiscordClient client, MessageReactionsClearEven
168168 return Task . CompletedTask ;
169169 }
170170
171- ~ ReactionCollector ( )
172- {
173- this . Dispose ( ) ;
174- }
175-
176171 /// <summary>
177172 /// Disposes this EventWaiter
178173 /// </summary>
179174 public void Dispose ( )
180175 {
181- this . _client = null ;
176+ this . _client = null ! ;
177+
178+ if ( this . _reactionAddHandler != null )
179+ this . _reactionAddEvent ? . Unregister ( this . _reactionAddHandler ) ;
182180
183- this . _reactionAddEvent . Unregister ( this . _reactionAddHandler ) ;
184- this . _reactionRemoveEvent . Unregister ( this . _reactionRemoveHandler ) ;
185- this . _reactionClearEvent . Unregister ( this . _reactionClearHandler ) ;
181+ if ( this . _reactionRemoveHandler != null )
182+ this . _reactionRemoveEvent ? . Unregister ( this . _reactionRemoveHandler ) ;
186183
187- this . _reactionAddEvent = null ;
188- this . _reactionAddHandler = null ;
189- this . _reactionRemoveEvent = null ;
190- this . _reactionRemoveHandler = null ;
191- this . _reactionClearEvent = null ;
192- this . _reactionClearHandler = null ;
184+ if ( this . _reactionClearHandler != null )
185+ this . _reactionClearEvent ? . Unregister ( this . _reactionClearHandler ) ;
193186
194- this . _requests . Clear ( ) ;
195- this . _requests = null ;
187+ this . _reactionAddEvent = null ! ;
188+ this . _reactionAddHandler = null ! ;
189+ this . _reactionRemoveEvent = null ! ;
190+ this . _reactionRemoveHandler = null ! ;
191+ this . _reactionClearEvent = null ! ;
192+ this . _reactionClearHandler = null ! ;
193+
194+ this . _requests ? . Clear ( ) ;
195+ this . _requests = null ! ;
196+
197+ // Satisfy rule CA1816. Can be removed if this class is sealed.
198+ GC . SuppressFinalize ( this ) ;
196199 }
197200 }
198201
@@ -214,19 +217,16 @@ public ReactionCollectRequest(DiscordMessage msg, TimeSpan timeout)
214217 this . _ct . Token . Register ( ( ) => this . _tcs . TrySetResult ( null ) ) ;
215218 }
216219
217- ~ ReactionCollectRequest ( )
218- {
219- this . Dispose ( ) ;
220- }
221-
222220 public void Dispose ( )
223221 {
224- GC . SuppressFinalize ( this ) ;
225222 this . _ct . Dispose ( ) ;
226223 this . _tcs = null ;
227224 this . _message = null ;
228225 this . _collected ? . Clear ( ) ;
229226 this . _collected = null ;
227+
228+ // Satisfy rule CA1816. Can be removed if this class is sealed.
229+ GC . SuppressFinalize ( this ) ;
230230 }
231231 }
232232
0 commit comments