Skip to content

Commit 1ec0d9d

Browse files
committed
Added catching the OperationCanceledExceptions.
1 parent 6dac808 commit 1ec0d9d

File tree

1 file changed

+49
-16
lines changed

1 file changed

+49
-16
lines changed

Rubberduck.Parsing/VBA/ParseCoordinator.cs

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,27 @@ private void ParseComponents(List<IVBComponent> components, CancellationToken to
221221
options.CancellationToken = token;
222222
options.MaxDegreeOfParallelism = _maxDegreeOfParserParallelism;
223223

224-
Parallel.ForEach(components,
225-
options,
226-
component =>
224+
try
225+
{
226+
Parallel.ForEach(components,
227+
options,
228+
component =>
229+
{
230+
State.ClearStateCache(component);
231+
var finishedParseTask = FinishedParseComponentTask(component, token);
232+
ProcessComponentParseResults(component, finishedParseTask);
233+
}
234+
);
235+
}
236+
catch (AggregateException exception)
237+
{
238+
if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
227239
{
228-
State.ClearStateCache(component);
229-
var finishedParseTask = FinishedParseComponentTask(component, token);
230-
ProcessComponentParseResults(component, finishedParseTask);
240+
return;
231241
}
232-
);
242+
throw;
243+
}
244+
233245
State.EvaluateParserState();
234246
}
235247

@@ -299,22 +311,43 @@ private void ResolveAllDeclarations(List<IVBComponent> components, CancellationT
299311
var options = new ParallelOptions();
300312
options.CancellationToken = token;
301313
options.MaxDegreeOfParallelism = _maxDegreeOfParserParallelism;
302-
303-
Parallel.ForEach(components,
304-
options,
305-
component =>
314+
try
315+
{
316+
Parallel.ForEach(components,
317+
options,
318+
component =>
319+
{
320+
var qualifiedName = new QualifiedModuleName(component);
321+
ResolveDeclarations(qualifiedName.Component,
322+
State.ParseTrees.Find(s => s.Key == qualifiedName).Value);
323+
}
324+
);
325+
}
326+
catch (AggregateException exception)
327+
{
328+
if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
306329
{
307-
var qualifiedName = new QualifiedModuleName(component);
308-
ResolveDeclarations(qualifiedName.Component,
309-
State.ParseTrees.Find(s => s.Key == qualifiedName).Value);
330+
return;
310331
}
311-
);
332+
throw;
333+
}
312334
}
313335

314336

315337
private void ResolveReferences(CancellationToken token)
316338
{
317-
Task.WaitAll(ResolveReferencesAsync(token));
339+
try
340+
{
341+
Task.WaitAll(ResolveReferencesAsync(token));
342+
}
343+
catch (AggregateException exception)
344+
{
345+
if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
346+
{
347+
return;
348+
}
349+
throw;
350+
}
318351
}
319352

320353

0 commit comments

Comments
 (0)