Browse Source

Fixed asynchronous custom tool bug

* Changed pending tasks to a queue rather than a list.
 * Ensure that pending tasks isn't empty before trying to execute the next task.
pull/12/head
Charles Weld 15 years ago committed by Daniel Grunwald
parent
commit
e9bccd9269
  1. 18
      src/Main/Base/Project/Src/Project/CustomTool.cs

18
src/Main/Base/Project/Src/Project/CustomTool.cs

@ -7,8 +7,9 @@ using System.CodeDom.Compiler;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text.RegularExpressions; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
@ -293,7 +294,7 @@ namespace ICSharpCode.SharpDevelop.Project
} }
static bool initialized; static bool initialized;
static List<CustomToolRun> toolRuns = new List<CustomToolRun>(); static Queue<CustomToolRun> toolRuns = new Queue<CustomToolRun>();
static Dictionary<string, CustomToolDescriptor> toolDict; static Dictionary<string, CustomToolDescriptor> toolDict;
static List<CustomToolDescriptor> customToolList; static List<CustomToolDescriptor> customToolList;
static CustomToolRun activeToolRun; static CustomToolRun activeToolRun;
@ -390,9 +391,7 @@ namespace ICSharpCode.SharpDevelop.Project
WorkbenchSingleton.AssertMainThread(); WorkbenchSingleton.AssertMainThread();
string fileName = baseItem.FileName; string fileName = baseItem.FileName;
if (toolRuns.Exists(delegate(CustomToolRun run) { if (toolRuns.Any(run => FileUtility.IsEqualFileName(run.file, fileName)))
return FileUtility.IsEqualFileName(run.file, fileName);
}))
{ {
// file already in queue, do not enqueue it again // file already in queue, do not enqueue it again
return; return;
@ -439,7 +438,7 @@ namespace ICSharpCode.SharpDevelop.Project
static void RunCustomTool(CustomToolRun run) static void RunCustomTool(CustomToolRun run)
{ {
if (activeToolRun != null) { if (activeToolRun != null) {
toolRuns.Add(run); toolRuns.Enqueue(run);
} else { } else {
try { try {
run.customTool.GenerateCode(run.baseItem, run.context); run.customTool.GenerateCode(run.baseItem, run.context);
@ -462,9 +461,12 @@ namespace ICSharpCode.SharpDevelop.Project
WorkbenchSingleton.SafeThreadAsyncCall( WorkbenchSingleton.SafeThreadAsyncCall(
delegate { delegate {
activeToolRun = null; activeToolRun = null;
CustomToolRun nextRun = toolRuns[0]; if(toolRuns.Count > 0) {
toolRuns.RemoveAt(0); CustomToolRun nextRun = toolRuns.Dequeue();
if(nextRun != null) {
RunCustomTool(nextRun); RunCustomTool(nextRun);
}
}
}); });
} }
} }

Loading…
Cancel
Save