From e2198a0c67aabd240be8baaf6824a020fc315c6e Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 3 Sep 2015 09:38:57 +0300 Subject: [PATCH] Added RunJobs to Dispatcher (needed for designer) --- src/Perspex.Base/Threading/Dispatcher.cs | 8 ++++ src/Perspex.Base/Threading/MainLoop.cs | 54 ++++++++++++++---------- 2 files changed, 39 insertions(+), 23 deletions(-) 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; } }