Browse Source

Shut down build worker processes after the build has finished.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/dotnet4@4262 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
ba0cb0bd43
  1. 1
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/GacReferencePanel.cs
  2. 2
      src/Main/Base/Project/Src/Project/BuildEngine.cs
  3. 17
      src/Main/Base/Project/Src/Project/MSBuildEngine/ParallelMSBuildManager.cs
  4. 28
      src/Main/Base/Project/Src/Services/ParserService/ParserService.cs

1
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/GacReferencePanel.cs

@ -180,7 +180,6 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -180,7 +180,6 @@ namespace ICSharpCode.SharpDevelop.Gui
listView.Items.AddRange(shortItemList);
Thread resolveVersionsThread = new Thread(ResolveVersionsThread);
resolveVersionsThread.SetApartmentState(ApartmentState.STA);
resolveVersionsThread.IsBackground = true;
resolveVersionsThread.Name = "resolveVersionsThread";
resolveVersionsThread.Priority = ThreadPriority.BelowNormal;

2
src/Main/Base/Project/Src/Project/BuildEngine.cs

@ -208,6 +208,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -208,6 +208,7 @@ namespace ICSharpCode.SharpDevelop.Project
options.SolutionPlatform = solution.Preferences.ActivePlatform;
BuildEngine engine = new BuildEngine(options, project);
ParallelMSBuildManager.EnableBuildEngine(); // matching disable call will be done in BuildEngine.ReportDone()
engine.buildStart = DateTime.Now;
engine.combinedBuildFeedbackSink = realtimeBuildFeedbackSink;
engine.progressMonitor = progressMonitor;
@ -551,6 +552,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -551,6 +552,7 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary>
void ReportDone()
{
ParallelMSBuildManager.DisableBuildEngine();
if (combinedBuildFeedbackSink != null) {
if (combinedBuildFeedbackSink is MessageViewSink) {
// Special case GUI-builds so that they have more information available:

17
src/Main/Base/Project/Src/Project/MSBuildEngine/ParallelMSBuildManager.cs

@ -35,10 +35,17 @@ namespace ICSharpCode.SharpDevelop.Project @@ -35,10 +35,17 @@ namespace ICSharpCode.SharpDevelop.Project
static readonly object enableDisableLock = new object();
static int enableCount;
static void EnableBuildEngine()
/// <summary>
/// Enables the underlying build engine.
/// Call this method only if you are requesting multiple builds in a series (e.g. building the solution).
/// A counter is increment to remember how many users of this class need the build engine.
/// For each EnableBuildEngine() call, you need to call DisableBuildEngine() exactly once!
/// </summary>
public static void EnableBuildEngine()
{
lock (enableDisableLock) {
if (enableCount == 0) {
LoggingService.Info("ParallelMSBuildManager starting up...");
BuildParameters parameters = new BuildParameters();
parameters.Loggers = new ILogger[] {
new CentralLogger(),
@ -46,19 +53,25 @@ namespace ICSharpCode.SharpDevelop.Project @@ -46,19 +53,25 @@ namespace ICSharpCode.SharpDevelop.Project
new ConsoleLogger(LoggerVerbosity.Normal),
#endif
};
parameters.EnableNodeReuse = false;
parameters.MaxNodeCount = BuildOptions.DefaultParallelProjectCount;
BuildManager.DefaultBuildManager.BeginBuild(parameters);
}
enableCount++;
}
}
static void DisableBuildEngine()
/// <summary>
/// Decrements the counter and disables the underlying build engine if the counter reaches 0.
/// </summary>
public static void DisableBuildEngine()
{
lock (enableDisableLock) {
enableCount--;
if (enableCount == 0) {
BuildManager.DefaultBuildManager.EndBuild();
BuildManager.DefaultBuildManager.ResetCaches();
LoggingService.Info("ParallelMSBuildManager shut down!");
}
}
}

28
src/Main/Base/Project/Src/Services/ParserService/ParserService.cs

@ -129,7 +129,6 @@ namespace ICSharpCode.SharpDevelop @@ -129,7 +129,6 @@ namespace ICSharpCode.SharpDevelop
}
}
loadSolutionProjectsThread = new Thread(new ThreadStart(LoadSolutionProjects));
loadSolutionProjectsThread.SetApartmentState(ApartmentState.STA); // allow loadSolutionProjects thread access to MSBuild
loadSolutionProjectsThread.Name = "loadSolutionProjects";
loadSolutionProjectsThread.Priority = ThreadPriority.BelowNormal;
loadSolutionProjectsThread.IsBackground = true;
@ -174,19 +173,25 @@ namespace ICSharpCode.SharpDevelop @@ -174,19 +173,25 @@ namespace ICSharpCode.SharpDevelop
}
WorkbenchSingleton.SafeThreadAsyncCall(ProjectService.ParserServiceCreatedProjectContents);
try {
int workAmount = 0;
// multiply Count with 2 so that the progress bar is only at 50% when references are done
progressMonitor.BeginTask("Loading references...", createdContents.Count * 2, false);
int workAmount = 0;
for (int i = 0; i < createdContents.Count; i++) {
if (abortLoadSolutionProjectsThread) return;
ParseProjectContent newContent = createdContents[i];
progressMonitor.WorkDone = i;
try {
newContent.Initialize1(progressMonitor);
workAmount += newContent.GetInitializationWorkAmount();
} catch (Exception e) {
MessageService.ShowError(e, "Error while initializing project references:" + newContent);
ParallelMSBuildManager.EnableBuildEngine();
try {
for (int i = 0; i < createdContents.Count; i++) {
if (abortLoadSolutionProjectsThread) return;
ParseProjectContent newContent = createdContents[i];
progressMonitor.WorkDone = i;
try {
newContent.Initialize1(progressMonitor);
workAmount += newContent.GetInitializationWorkAmount();
} catch (Exception e) {
MessageService.ShowError(e, "Error while initializing project references:" + newContent);
}
}
} finally {
ParallelMSBuildManager.DisableBuildEngine();
}
// multiply workamount with two and start at workAmount so that the progress bar continues
// from 50% towards 100%.
@ -297,7 +302,6 @@ namespace ICSharpCode.SharpDevelop @@ -297,7 +302,6 @@ namespace ICSharpCode.SharpDevelop
if (reParseThread == null) {
LoggingService.Info("Starting reParse thread");
reParseThread = new Thread(new ThreadStart(ReparseProjects));
reParseThread.SetApartmentState(ApartmentState.STA); // allow reParseThread access to MSBuild
reParseThread.Name = "reParse";
reParseThread.Priority = ThreadPriority.BelowNormal;
reParseThread.IsBackground = true;

Loading…
Cancel
Save