From 142f099be41a1879e8e5cc95b318e38fde679f74 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 26 Feb 2010 15:46:23 +0000 Subject: [PATCH] Fixed NullReferenceException in ICSharpCode.SharpDevelop.LoadSolutionProjects.JobQueue.RunThread() when canceling LoadSolutionProjects thread. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5550 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../ParserService/LoadSolutionProjects.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Main/Base/Project/Src/Services/ParserService/LoadSolutionProjects.cs b/src/Main/Base/Project/Src/Services/ParserService/LoadSolutionProjects.cs index e23e3b8d12..398f004e6f 100644 --- a/src/Main/Base/Project/Src/Services/ParserService/LoadSolutionProjects.cs +++ b/src/Main/Base/Project/Src/Services/ParserService/LoadSolutionProjects.cs @@ -224,10 +224,16 @@ namespace ICSharpCode.SharpDevelop double totalWork, workDone; IProgressMonitor progressMonitor; lock (lockObj) { - if (actions.Count == 0) { + // enqueued null: quit thread and restart (used for cancellation) + if (actions.Count == 0 || this.actions.Peek() == null) { this.threadIsRunning = false; this.progressMonitor.Dispose(); this.progressMonitor = null; + // restart if necessary: + if (actions.Count > 0) { + actions.Dequeue(); // dequeue the null + WorkbenchSingleton.SafeThreadAsyncCall(StartRunningIfRequired); + } return; } task = this.actions.Dequeue(); @@ -258,12 +264,14 @@ namespace ICSharpCode.SharpDevelop cancellationSource.Cancel(); actions.Clear(); cancellationSource = new CancellationTokenSource(); - if (progressMonitor != null) { - progressMonitor.Dispose(); - progressMonitor = null; - } this.totalWork = 0; this.workDone = 0; + // progress monitor gets disposed when the worker thread exits + if (threadIsRunning) { + actions.Enqueue(null); // force worker thread to restart using a new progress monitor + // This is necessary so that actions enqueued after the Clear() call get executed using + // the fresh CancellationToken. + } } } }