diff --git a/src/Perspex.Base/Threading/Dispatcher.cs b/src/Perspex.Base/Threading/Dispatcher.cs
index af6f1d58af..31191d587c 100644
--- a/src/Perspex.Base/Threading/Dispatcher.cs
+++ b/src/Perspex.Base/Threading/Dispatcher.cs
@@ -50,6 +50,14 @@ namespace Perspex.Threading
this.mainLoop.Run(cancellationToken);
}
+ ///
+ /// Runs continuations pushed on the loop.
+ ///
+ public void RunJobs()
+ {
+ this.mainLoop.RunJobs();
+ }
+
///
/// Invokes a method on the dispatcher thread.
///
diff --git a/src/Perspex.Base/Threading/MainLoop.cs b/src/Perspex.Base/Threading/MainLoop.cs
index e7efefacc1..009d331b28 100644
--- a/src/Perspex.Base/Threading/MainLoop.cs
+++ b/src/Perspex.Base/Threading/MainLoop.cs
@@ -42,37 +42,45 @@ namespace Perspex.Win32.Threading
{
while (!cancellationToken.IsCancellationRequested)
{
- Job job = null;
+ RunJobs();
- while (job != null || this.queue.Count > 0)
- {
- if (job == null)
- {
- lock (this.queue)
- {
- job = this.queue.Dequeue();
- }
- }
+ platform.ProcessMessage();
+ }
+ }
- if (job.Priority < DispatcherPriority.Input && platform.HasMessages())
- {
- break;
- }
+ ///
+ /// Runs continuations pushed on the loop.
+ ///
+ public void RunJobs()
+ {
+ Job job = null;
- try
- {
- job.Action();
- job.TaskCompletionSource.SetResult(null);
- }
- catch (Exception e)
+ while (job != null || this.queue.Count > 0)
+ {
+ if (job == null)
+ {
+ lock (this.queue)
{
- job.TaskCompletionSource.SetException(e);
+ job = this.queue.Dequeue();
}
+ }
- job = null;
+ if (job.Priority < DispatcherPriority.Input && platform.HasMessages())
+ {
+ break;
}
- platform.ProcessMessage();
+ try
+ {
+ job.Action();
+ job.TaskCompletionSource.SetResult(null);
+ }
+ catch (Exception e)
+ {
+ job.TaskCompletionSource.SetException(e);
+ }
+
+ job = null;
}
}
diff --git a/src/Windows/Perspex.Designer/AppHost/PerspexAppHost.cs b/src/Windows/Perspex.Designer/AppHost/PerspexAppHost.cs
index 5e099e6eb0..5d31605d43 100644
--- a/src/Windows/Perspex.Designer/AppHost/PerspexAppHost.cs
+++ b/src/Windows/Perspex.Designer/AppHost/PerspexAppHost.cs
@@ -6,6 +6,7 @@ using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
+using System.Windows.Forms;
using Perspex.Designer.Comm;
namespace Perspex.Designer.AppHost
@@ -130,7 +131,13 @@ namespace Perspex.Designer.AppHost
LookupStaticMethod("Perspex.Direct2D1.Direct2D1Platform", "Initialize").Invoke(null, null);
LookupStaticMethod("Perspex.Win32.Win32Platform", "InitializeEmbedded").Invoke(null, null);
+ dynamic dispatcher =
+ LookupType("Perspex.Threading.Dispatcher")
+ .GetProperty("UIThread", BindingFlags.Static | BindingFlags.Public)
+ .GetValue(null);
+
+
var xamlFactory = Activator.CreateInstance(LookupType("Perspex.Markup.Xaml.Context.PerspexParserFactory"));
dynamic xamlLoader =
@@ -138,6 +145,10 @@ namespace Perspex.Designer.AppHost
_xamlReader = (stream, root) => xamlLoader.Load(stream, root);
_host = new WindowHost();
+ new Timer() {Interval = 10, Enabled = true}.Tick += delegate
+ {
+ dispatcher.RunJobs();
+ };
_comm.SendMessage(new WindowCreatedMessage(_host.Handle));
_initSuccess = true;
}