@@ -51,13 +51,20 @@ public virtual async Task<CodeAction> GetFixAsync(
5151
5252 var documents = documentsAndDiagnosticsToFixMap . Keys . ToImmutableArray ( ) ;
5353 var fixesBag = new List < CodeAction > [ documents . Length ] ;
54- var options = new ParallelOptions ( ) { CancellationToken = fixAllContext . CancellationToken } ;
55- Parallel . ForEach ( documents , options , ( document , state , index ) =>
54+ var fixOperations = new List < Task > ( documents . Length ) ;
55+ for ( int index = 0 ; index < documents . Length ; index ++ )
5656 {
57- fixAllContext . CancellationToken . ThrowIfCancellationRequested ( ) ;
57+ if ( fixAllContext . CancellationToken . IsCancellationRequested )
58+ {
59+ break ;
60+ }
61+
62+ var document = documents [ index ] ;
5863 fixesBag [ index ] = new List < CodeAction > ( ) ;
59- this . AddDocumentFixesAsync ( document , documentsAndDiagnosticsToFixMap [ document ] , fixesBag [ index ] . Add , fixAllContext ) . Wait ( fixAllContext . CancellationToken ) ;
60- } ) ;
64+ fixOperations . Add ( this . AddDocumentFixesAsync ( document , documentsAndDiagnosticsToFixMap [ document ] , fixesBag [ index ] . Add , fixAllContext ) ) ;
65+ }
66+
67+ await Task . WhenAll ( fixOperations ) . ConfigureAwait ( false ) ;
6168
6269 if ( fixesBag . Any ( fixes => fixes . Count > 0 ) )
6370 {
@@ -129,15 +136,23 @@ public virtual async Task<CodeAction> GetFixAsync(
129136 {
130137 if ( projectsAndDiagnosticsToFixMap != null && projectsAndDiagnosticsToFixMap . Any ( ) )
131138 {
132- var options = new ParallelOptions ( ) { CancellationToken = fixAllContext . CancellationToken } ;
133139 var fixesBag = new List < CodeAction > [ projectsAndDiagnosticsToFixMap . Count ] ;
134- Parallel . ForEach ( projectsAndDiagnosticsToFixMap . Keys , options , ( project , state , index ) =>
140+ var fixOperations = new List < Task > ( projectsAndDiagnosticsToFixMap . Count ) ;
141+ int index = - 1 ;
142+ foreach ( var project in projectsAndDiagnosticsToFixMap . Keys )
135143 {
136- fixAllContext . CancellationToken . ThrowIfCancellationRequested ( ) ;
144+ if ( fixAllContext . CancellationToken . IsCancellationRequested )
145+ {
146+ break ;
147+ }
148+
149+ index ++ ;
137150 var diagnostics = projectsAndDiagnosticsToFixMap [ project ] ;
138151 fixesBag [ index ] = new List < CodeAction > ( ) ;
139- this . AddProjectFixesAsync ( project , diagnostics , fixesBag [ index ] . Add , fixAllContext ) . Wait ( fixAllContext . CancellationToken ) ;
140- } ) ;
152+ fixOperations . Add ( this . AddProjectFixesAsync ( project , diagnostics , fixesBag [ index ] . Add , fixAllContext ) ) ;
153+ }
154+
155+ await Task . WhenAll ( fixOperations ) . ConfigureAwait ( false ) ;
141156
142157 if ( fixesBag . Any ( fixes => fixes . Count > 0 ) )
143158 {
0 commit comments