Skip to content

Commit d4a6301

Browse files
committed
simplified cancellation in Dispose
1 parent e93a994 commit d4a6301

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,16 @@ private Task ParseAsync(IVBComponent component, CancellationTokenSource token, T
507507
return task;
508508
}
509509

510-
private void Cancel()
510+
private void Cancel(bool createNewTokenSource = true)
511511
{
512512
lock (_cancellationTokens[0])
513513
{
514514
_cancellationTokens[0].Cancel();
515-
516515
_cancellationTokens[0].Dispose();
517-
_cancellationTokens.Add(new CancellationTokenSource());
516+
if (createNewTokenSource)
517+
{
518+
_cancellationTokens.Add(new CancellationTokenSource());
519+
}
518520
_cancellationTokens.RemoveAt(0);
519521
}
520522
}
@@ -641,16 +643,7 @@ private void ResolveReferences(DeclarationFinder finder, IVBComponent component,
641643
public void Dispose()
642644
{
643645
State.ParseRequest -= ReparseRequested;
644-
645-
if (_cancellationTokens[0] != null)
646-
{
647-
try
648-
{
649-
_cancellationTokens[0].Cancel();
650-
_cancellationTokens[0].Dispose();
651-
}
652-
catch (ObjectDisposedException) { /* todo: avoid this being thrown in the first place */ }
653-
}
646+
Cancel(false);
654647
}
655648
}
656649
}

0 commit comments

Comments
 (0)