Skip to content

Commit cb3fcc8

Browse files
committed
Prevent hangs on parse cancelations. Go me!
1 parent 1367ceb commit cb3fcc8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

RetailCoder.VBE/App.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private void ParseComponentAsync(VBComponent component, bool resolve = true)
154154
var tokenSource = RenewTokenSource(component);
155155

156156
var token = tokenSource.Token;
157-
_parser.ParseAsync(component, token).Wait(token);
157+
_parser.ParseAsync(component, token);
158158

159159
if (resolve && !token.IsCancellationRequested)
160160
{

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ public RubberduckParser(RubberduckParserState state)
2828
private readonly RubberduckParserState _state;
2929
public RubberduckParserState State { get { return _state; } }
3030

31-
public async Task ParseAsync(VBComponent vbComponent, CancellationToken token)
31+
public Task ParseAsync(VBComponent vbComponent, CancellationToken token)
3232
{
3333
var component = vbComponent;
3434

35+
token.ThrowIfCancellationRequested();
3536
var parseTask = Task.Run(() => ParseInternal(component, token), token);
3637

3738
try
3839
{
39-
await parseTask;
40+
token.ThrowIfCancellationRequested();
41+
parseTask.Wait(token);
4042
}
4143
catch (SyntaxErrorException exception)
4244
{
@@ -45,7 +47,9 @@ public async Task ParseAsync(VBComponent vbComponent, CancellationToken token)
4547
catch (OperationCanceledException)
4648
{
4749
// no need to blow up
48-
}
50+
}
51+
52+
return null;
4953
}
5054

5155
public void Resolve(CancellationToken token)

0 commit comments

Comments
 (0)