@@ -21,6 +21,7 @@ You should have received a copy of the GNU General Public License
2121using System . Collections . Generic ;
2222using System . ComponentModel . Composition ;
2323using System . Linq ;
24+ using System . Threading ;
2425using System . Threading . Tasks ;
2526using System . Windows ;
2627using System . Windows . Controls ;
@@ -63,6 +64,7 @@ sealed class StringReferencesService : IStringReferencesService {
6364 private readonly StringsControlVM vm ;
6465 private readonly Dispatcher dispatcher ;
6566 private ModuleDef [ ] selectedModules = [ ] ;
67+ private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource ( ) ;
6668
6769 public StringsControl UIObject { get ; }
6870
@@ -147,12 +149,15 @@ private void AnalyzeSelectedModules() {
147149 dotNetImageService
148150 ) ;
149151
152+ cancellationTokenSource . Cancel ( ) ;
153+ cancellationTokenSource = new CancellationTokenSource ( ) ;
154+
150155 vm . StringLiterals . Clear ( ) ;
151156
152157 Task . Factory . StartNew ( ( ) => {
153158 AnalyzeMetadataRoots ( context ) ;
154159 AnalyzeModules ( context ) ;
155- } ) ;
160+ } , cancellationTokenSource . Token ) ;
156161 }
157162
158163 private void AnalyzeMetadataRoots ( StringReferenceContext context ) {
@@ -183,7 +188,10 @@ private void AnalyzeMetadataRoots(StringReferenceContext context) {
183188 }
184189
185190 private void AnalyzeModules ( StringReferenceContext context ) {
186- Parallel . ForEach ( selectedModules . SelectMany ( x => x . GetTypes ( ) ) , type => {
191+ var parallelOptions = new ParallelOptions {
192+ CancellationToken = cancellationTokenSource . Token ,
193+ } ;
194+ Parallel . ForEach ( selectedModules . SelectMany ( x => x . GetTypes ( ) ) , parallelOptions , type => {
187195 var typeContext = new ObjectContext {
188196 Context = context ,
189197 Module = type . Module ,
0 commit comments