diff --git a/src/Main/Base/Project/Util/ReactiveExtensions.cs b/src/Main/Base/Project/Util/ReactiveExtensions.cs index b26b6687fc..ea4d7d253f 100644 --- a/src/Main/Base/Project/Util/ReactiveExtensions.cs +++ b/src/Main/Base/Project/Util/ReactiveExtensions.cs @@ -64,7 +64,7 @@ namespace ICSharpCode.SharpDevelop public TaskToObserverSubscription(Func, Task> func, IObserver observer) { this.observer = observer; - func(cts.Token, Callback).ContinueWith(TaskCompleted); + func(cts.Token, Callback).ContinueWith(TaskCompleted).FireAndForget(); } public TaskToObserverSubscription(Func, Task> func, IProgressMonitor progressMonitor, IObserver observer) @@ -72,7 +72,7 @@ namespace ICSharpCode.SharpDevelop this.observer = observer; this.progressMonitor = progressMonitor; this.childProgressMonitor = progressMonitor.CreateSubTask(1, cts.Token); - func(childProgressMonitor, Callback).ContinueWith(TaskCompleted); + func(childProgressMonitor, Callback).ContinueWith(TaskCompleted).FireAndForget(); } void Callback(T item) diff --git a/src/Main/SharpDevelop/Project/Build/BuildEngine.cs b/src/Main/SharpDevelop/Project/Build/BuildEngine.cs index 6b974904dc..6a8698c0af 100644 --- a/src/Main/SharpDevelop/Project/Build/BuildEngine.cs +++ b/src/Main/SharpDevelop/Project/Build/BuildEngine.cs @@ -23,138 +23,6 @@ namespace ICSharpCode.SharpDevelop.Project /// sealed class BuildEngine { - #region Building in the SharpDevelop GUI - /*static CancellationTokenSource guiBuildCancellation; - static IAnalyticsMonitorTrackedFeature guiBuildTrackedFeature; - - /// - /// Starts to run a build inside the SharpDevelop GUI. - /// Only one build can run inside the GUI at one time. - /// - /// The project/solution to build. - /// The build options. - public static void BuildInGui(IBuildable project, BuildOptions options) - { - if (project == null) - throw new ArgumentNullException("project"); - if (options == null) - throw new ArgumentNullException("options"); - WorkbenchSingleton.AssertMainThread(); - if (guiBuildCancellation != null) { - BuildResults results = new BuildResults(); - SD.StatusBar.SetMessage(Core.ResourceService.GetString("MainWindow.CompilerMessages.MSBuildAlreadyRunning")); - BuildError error = new BuildError(null, Core.ResourceService.GetString("MainWindow.CompilerMessages.MSBuildAlreadyRunning")); - results.Add(error); - TaskService.Add(new SDTask(error)); - results.Result = BuildResultCode.MSBuildAlreadyRunning; - if (options.Callback != null) { - options.Callback(results); - } - } else { - guiBuildCancellation = new CancellationTokenSource(); - IProgressMonitor progressMonitor = SD.StatusBar.CreateProgressMonitor(guiBuildCancellation.Token); - guiBuildTrackedFeature = SD.AnalyticsMonitor.TrackFeature("ICSharpCode.SharpDevelop.Project.BuildEngine.Build"); - SD.StatusBar.SetMessage(StringParser.Parse("${res:MainWindow.CompilerMessages.BuildVerb}...")); - ProjectService.RaiseEventBuildStarted(new BuildEventArgs(project, options)); - StartBuild(project, options, - new MessageViewSink(TaskService.BuildMessageViewCategory, progressMonitor, SD.StatusBar)); - } - } - - /// - /// Gets whether there is a build currently running inside the SharpDevelop GUI. - /// - public static bool IsGuiBuildRunning { - get { - WorkbenchSingleton.AssertMainThread(); - return guiBuildCancellation != null; - } - } - - /// - /// Cancels the build currently running inside the SharpDevelop GUI. - /// This method does nothing if no build is running. - /// - public static void CancelGuiBuild() - { - WorkbenchSingleton.AssertMainThread(); - if (guiBuildCancellation != null) { - guiBuildCancellation.Cancel(); - } - } - - /// - /// This error message sink is used for GUI builds. - /// - sealed class MessageViewSink : IBuildFeedbackSink - { - MessageViewCategory messageView; - IProgressMonitor progressMonitor; - IStatusBarService statusBarService; - - public MessageViewSink(MessageViewCategory messageView, IProgressMonitor progressMonitor, IStatusBarService statusBarService) - { - Debug.Assert(messageView != null); - Debug.Assert(progressMonitor != null); - Debug.Assert(statusBarService != null); - - this.messageView = messageView; - this.progressMonitor = progressMonitor; - this.statusBarService = statusBarService; - } - - public IProgressMonitor ProgressMonitor { - get { return progressMonitor; } - } - - public void ReportError(BuildError error) - { - WorkbenchSingleton.SafeThreadAsyncCall( - delegate { - TaskService.Add(new SDTask(error)); - }); - } - - public void ReportMessage(string message) - { - messageView.AppendLine(message); - } - - public void Done(bool success) - { - throw new InvalidOperationException("The Done(IBuildable,BuildOptions,BuildResults) method should be called instead."); - } - - public void Done(IBuildable buildable, BuildOptions options, BuildResults results) - { - WorkbenchSingleton.SafeThreadAsyncCall( - delegate { - guiBuildCancellation = null; - if (guiBuildTrackedFeature != null) { - guiBuildTrackedFeature.EndTracking(); - guiBuildTrackedFeature = null; - } - string message; - if (results.Result == BuildResultCode.Cancelled) { - message = "${res:MainWindow.CompilerMessages.BuildCancelled}"; - } else { - if (results.Result == BuildResultCode.Success) - message = "${res:MainWindow.CompilerMessages.BuildFinished}"; - else - message = "${res:MainWindow.CompilerMessages.BuildFailed}"; - - if (results.ErrorCount > 0) - message += " " + results.ErrorCount + " error(s)"; - if (results.WarningCount > 0) - message += " " + results.WarningCount + " warning(s)"; - } - statusBarService.SetMessage(message); - ProjectService.RaiseEventBuildFinished(new BuildEventArgs(buildable, options, results)); - }); - } - }*/ - #endregion - #region StartBuild /// /// Starts to run a build. diff --git a/src/Main/SharpDevelop/Project/Build/BuildModifiedProjectsOnlyService.cs b/src/Main/SharpDevelop/Project/Build/BuildModifiedProjectsOnlyService.cs index 7ae9a71342..b7911bc287 100644 --- a/src/Main/SharpDevelop/Project/Build/BuildModifiedProjectsOnlyService.cs +++ b/src/Main/SharpDevelop/Project/Build/BuildModifiedProjectsOnlyService.cs @@ -19,7 +19,7 @@ namespace ICSharpCode.SharpDevelop.Project /// class BuildModifiedProjectsOnlyService { - static readonly Dictionary unmodifiedProjects = new Dictionary(); + readonly Dictionary unmodifiedProjects = new Dictionary(); public BuildModifiedProjectsOnlyService(IBuildService buildService) { @@ -83,7 +83,7 @@ namespace ICSharpCode.SharpDevelop.Project LoggingService.Debug(pair.Key.Name + ": " + pair.Value); } } - return new WrapperFactory(setting).GetWrapper(buildable); + return new WrapperFactory(this, setting).GetWrapper(buildable); case BuildDetection.RegularBuild: return buildable; default: @@ -141,10 +141,12 @@ namespace ICSharpCode.SharpDevelop.Project { public readonly BuildDetection Setting; public readonly CompilationPass CurrentPass = new CompilationPass(); + internal readonly BuildModifiedProjectsOnlyService Service; readonly Dictionary dict = new Dictionary(); - public WrapperFactory(BuildDetection setting) + public WrapperFactory(BuildModifiedProjectsOnlyService service, BuildDetection setting) { + this.Service = service; this.Setting = setting; } @@ -163,11 +165,13 @@ namespace ICSharpCode.SharpDevelop.Project { internal readonly IBuildable wrapped; internal readonly WrapperFactory factory; + internal readonly BuildModifiedProjectsOnlyService service; public Wrapper(IBuildable wrapped, WrapperFactory factory) { this.wrapped = wrapped; this.factory = factory; + this.service = factory.Service; } public string Name { @@ -217,8 +221,8 @@ namespace ICSharpCode.SharpDevelop.Project if (p == null) { return await wrapped.BuildAsync(options, feedbackSink, progressMonitor); } else { - lock (unmodifiedProjects) { - if (!unmodifiedProjects.TryGetValue(p, out lastCompilationPass)) { + lock (service.unmodifiedProjects) { + if (!service.unmodifiedProjects.TryGetValue(p, out lastCompilationPass)) { lastCompilationPass = null; } } @@ -240,8 +244,8 @@ namespace ICSharpCode.SharpDevelop.Project lastCompilationPass = factory.CurrentPass; var success = await wrapped.BuildAsync(options, feedbackSink, progressMonitor); if (success) { - lock (unmodifiedProjects) { - unmodifiedProjects[p] = factory.CurrentPass; + lock (service.unmodifiedProjects) { + service.unmodifiedProjects[p] = factory.CurrentPass; } } return success;