Skip to content

Commit 2c9e982

Browse files
authored
fix(interactivity): Remove event unregistration and clean up dispose (#2041)
* fix(interactivity): Remove event unregistration and clean up dispose * Also fix dispose methods in ReactionCollector
1 parent a89cc99 commit 2c9e982

2 files changed

Lines changed: 5 additions & 47 deletions

File tree

DSharpPlus.Interactivity/EventHandling/EventWaiter.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,10 @@ public void Dispose()
128128
{
129129
return;
130130
}
131-
131+
132132
this.disposed = true;
133-
134-
if (this.@event != null && this.handler != null)
135-
{
136-
this.@event.Unregister(this.handler);
137-
}
138-
139-
this.@event = null!;
140-
this.handler = null!;
141-
this.client = null!;
142-
143-
this.matchrequests?.Clear();
144-
145-
this.collectrequests?.Clear();
146-
147-
this.matchrequests = null!;
148-
this.collectrequests = null!;
133+
this.matchrequests.Clear();
134+
this.collectrequests.Clear();
149135

150136
// Satisfy rule CA1816. Can be removed if this class is sealed.
151137
GC.SuppressFinalize(this);

DSharpPlus.Interactivity/EventHandling/ReactionCollector.cs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -161,32 +161,7 @@ private Task HandleReactionClear(DiscordClient client, MessageReactionsClearedEv
161161
/// </summary>
162162
public void Dispose()
163163
{
164-
this.client = null!;
165-
166-
if (this.reactionAddHandler != null)
167-
{
168-
this.reactionAddEvent?.Unregister(this.reactionAddHandler);
169-
}
170-
171-
if (this.reactionRemoveHandler != null)
172-
{
173-
this.reactionRemoveEvent?.Unregister(this.reactionRemoveHandler);
174-
}
175-
176-
if (this.reactionClearHandler != null)
177-
{
178-
this.reactionClearEvent?.Unregister(this.reactionClearHandler);
179-
}
180-
181-
this.reactionAddEvent = null!;
182-
this.reactionAddHandler = null!;
183-
this.reactionRemoveEvent = null!;
184-
this.reactionRemoveHandler = null!;
185-
this.reactionClearEvent = null!;
186-
this.reactionClearHandler = null!;
187-
188-
this.requests?.Clear();
189-
this.requests = null!;
164+
this.requests.Clear();
190165

191166
// Satisfy rule CA1816. Can be removed if this class is sealed.
192167
GC.SuppressFinalize(this);
@@ -214,10 +189,7 @@ public ReactionCollectRequest(DiscordMessage msg, TimeSpan timeout)
214189
public void Dispose()
215190
{
216191
this.ct.Dispose();
217-
this.tcs = null;
218-
this.message = null;
219-
this.collected?.Clear();
220-
this.collected = null;
192+
this.collected.Clear();
221193

222194
// Satisfy rule CA1816. Can be removed if this class is sealed.
223195
GC.SuppressFinalize(this);

0 commit comments

Comments
 (0)