diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-27 17:52:40 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-27 17:52:40 +0300 |
commit | 753257a3bfa01d52139b934c91e748108e4e8b77 (patch) | |
tree | 13093f956e029d131e60e57ab469757fa962120c | |
parent | d7398891d21b5780d73413b2c2dbfb3c7a4ef7d2 (diff) |
Fix some continuations
Fixed some ContinueWith calls that needed to run on the UI thread
9 files changed, 32 insertions, 21 deletions
diff --git a/main/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft/SoftDebuggerEngine.cs b/main/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft/SoftDebuggerEngine.cs index 4e4228a49d..f9755a2573 100644 --- a/main/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft/SoftDebuggerEngine.cs +++ b/main/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft/SoftDebuggerEngine.cs @@ -35,6 +35,7 @@ using Mono.Debugging.Client; using MonoDevelop.Core; using MonoDevelop.Core.Execution; using MonoDevelop.Core.Assemblies; +using System.Threading.Tasks; namespace MonoDevelop.Debugger.Soft { @@ -167,7 +168,7 @@ namespace MonoDevelop.Debugger.Soft oper.Task.ContinueWith (t => { if (Exited != null) Exited (this, EventArgs.Empty); - }); + }, TaskScheduler.FromCurrentSynchronizationContext ()); } #region IProcess implementation diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/Extensions.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/Extensions.cs index 6b7db7d7a2..0ea39ad8b3 100644 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/Extensions.cs +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/Extensions.cs @@ -32,6 +32,7 @@ using MonoDevelop.Ide; using MonoDevelop.Ide.Gui; using MonoDevelop.Projects; using System.Collections.Generic; +using System.Threading.Tasks; namespace MonoDevelop.Debugger { @@ -83,7 +84,7 @@ namespace MonoDevelop.Debugger oper.Task.ContinueWith (t => { monitor.Dispose (); IdeApp.Workbench.CurrentLayout = oldLayout; - }); + }, TaskScheduler.FromCurrentSynchronizationContext ()); return oper; } @@ -107,7 +108,7 @@ namespace MonoDevelop.Debugger oper.Task.ContinueWith (t => { IdeApp.Workbench.CurrentLayout = oldLayout; - }); + }, TaskScheduler.FromCurrentSynchronizationContext ()); } } } diff --git a/main/src/addins/NUnit/Gui/TestPad.cs b/main/src/addins/NUnit/Gui/TestPad.cs index 5685fbc89d..5f80de59ba 100644 --- a/main/src/addins/NUnit/Gui/TestPad.cs +++ b/main/src/addins/NUnit/Gui/TestPad.cs @@ -45,6 +45,7 @@ using System.Linq; using MonoDevelop.Components; using MonoDevelop.Ide.Commands; using System.Collections.Generic; +using System.Threading.Tasks; namespace MonoDevelop.NUnit { @@ -488,7 +489,7 @@ namespace MonoDevelop.NUnit if (bringToFront) IdeApp.Workbench.GetPad<TestPad> ().BringToFront (); runningTestOperation = testService.RunTest (test, mode); - runningTestOperation.Task.ContinueWith (t => OnTestSessionCompleted ()); + runningTestOperation.Task.ContinueWith (t => OnTestSessionCompleted (), TaskScheduler.FromCurrentSynchronizationContext ()); return runningTestOperation; } diff --git a/main/src/addins/NUnit/Services/NUnitService.cs b/main/src/addins/NUnit/Services/NUnitService.cs index 2ecd85412b..1645b9d8b8 100644 --- a/main/src/addins/NUnit/Services/NUnitService.cs +++ b/main/src/addins/NUnit/Services/NUnitService.cs @@ -93,7 +93,7 @@ namespace MonoDevelop.NUnit public AsyncOperation RunTest (UnitTest test, IExecutionHandler context) { var result = RunTest (test, context, IdeApp.Preferences.BuildBeforeRunningTests); - result.Task.ContinueWith (t => OnTestSessionCompleted ()); + result.Task.ContinueWith (t => OnTestSessionCompleted (), TaskScheduler.FromCurrentSynchronizationContext ()); return result; } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/ProcessService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/ProcessService.cs index 86ca89f008..0a96e8fd7f 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/ProcessService.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/ProcessService.cs @@ -39,6 +39,7 @@ using MonoDevelop.Core; using MonoDevelop.Core.Assemblies; using MonoDevelop.Core.Instrumentation; using Mono.Addins; +using System.Threading.Tasks; namespace MonoDevelop.Core.Execution { @@ -156,7 +157,7 @@ namespace MonoDevelop.Core.Execution // p.EnableRaisingEvents = true; if (exited != null) - p.Task.ContinueWith (t => exited (p, EventArgs.Empty)); + p.Task.ContinueWith (t => exited (p, EventArgs.Empty), TaskScheduler.FromCurrentSynchronizationContext ()); Counters.ProcessesStarted++; p.Start (); @@ -209,7 +210,7 @@ namespace MonoDevelop.Core.Execution if (p != null) { if (exited != null) - p.Task.ContinueWith (t => exited (p, EventArgs.Empty)); + p.Task.ContinueWith (t => exited (p, EventArgs.Empty), TaskScheduler.FromCurrentSynchronizationContext ()); Counters.ProcessesStarted++; return p; } else { @@ -415,7 +416,7 @@ namespace MonoDevelop.Core.Execution this.exited = exited; this.operation = operation; this.console = console; - operation.Task.ContinueWith (t => OnOperationCompleted ()); + operation.Task.ContinueWith (t => OnOperationCompleted (), TaskScheduler.FromCurrentSynchronizationContext ()); cancelRegistration = console.CancellationToken.Register (operation.Cancel); } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs index 6578119afd..0a8b8def0c 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs @@ -297,6 +297,17 @@ namespace MonoDevelop.Core if (mainSynchronizationContext != null && value != null) throw new InvalidOperationException ("The main synchronization context has already been set"); mainSynchronizationContext = value; + taskScheduler = null; + } + } + + + static TaskScheduler taskScheduler; + public static TaskScheduler MainTaskScheduler { + get { + if (taskScheduler == null) + RunInMainThread (() => taskScheduler =TaskScheduler.FromCurrentSynchronizationContext ()).Wait (); + return taskScheduler; } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs index b4f2ba83d2..d4ba526f26 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs @@ -308,18 +308,14 @@ namespace MonoDevelop.Ide.Templates } //methods - public Task<bool> OpenCreatedSolution () + public async Task<bool> OpenCreatedSolution () { - var asyncOperation = IdeApp.Workspace.OpenWorkspaceItem (createdSolutionName); - return asyncOperation.ContinueWith (t => { - if (t.Result) { - foreach (string action in actions) { - IdeApp.Workbench.OpenDocument (Path.Combine (createdProjectInformation.ProjectBasePath, action)); - } - return true; - } - return false; - }); + if (await IdeApp.Workspace.OpenWorkspaceItem (createdSolutionName)) { + foreach (string action in actions) + IdeApp.Workbench.OpenDocument (Path.Combine (createdProjectInformation.ProjectBasePath, action)); + return true; + } + return false; } public WorkspaceItem CreateWorkspaceItem (ProjectCreateInformation cInfo) diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/FeedbackService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/FeedbackService.cs index 32e4e54210..3f194ee00e 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/FeedbackService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/FeedbackService.cs @@ -184,7 +184,7 @@ namespace MonoDevelop.Ide sw.Write (body); } } - ).ContinueWith (HandleResponse); + ).ContinueWith (HandleResponse, TaskScheduler.FromCurrentSynchronizationContext ()); } static void HandleResponse (Task<HttpWebResponse> t) diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs index d096632d8e..422ed15f08 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs @@ -245,7 +245,7 @@ namespace MonoDevelop.Ide if (IdeApp.Preferences.LoadPrevSolutionOnStartup && !startupInfo.HasSolutionFile && !IdeApp.Workspace.WorkspaceItemIsOpening && !IdeApp.Workspace.IsOpen) { openedProject = DesktopService.RecentFiles.GetProjects ().FirstOrDefault (); if (openedProject != null) - IdeApp.Workspace.OpenWorkspaceItem (openedProject.FileName).ContinueWith ((t) => IdeApp.OpenFiles (startupInfo.RequestedFileList)); + IdeApp.Workspace.OpenWorkspaceItem (openedProject.FileName).ContinueWith (t => IdeApp.OpenFiles (startupInfo.RequestedFileList), TaskScheduler.FromCurrentSynchronizationContext ()); } if (openedProject == null) IdeApp.OpenFiles (startupInfo.RequestedFileList); |