Browse Source

Fixed render updates

pull/148/head
Nikita Tsukanov 11 years ago
parent
commit
ea1acce696
  1. 8
      src/Perspex.Base/Threading/Dispatcher.cs
  2. 54
      src/Perspex.Base/Threading/MainLoop.cs
  3. 11
      src/Windows/Perspex.Designer/AppHost/PerspexAppHost.cs

8
src/Perspex.Base/Threading/Dispatcher.cs

@ -50,6 +50,14 @@ namespace Perspex.Threading
this.mainLoop.Run(cancellationToken);
}
/// <summary>
/// Runs continuations pushed on the loop.
/// </summary>
public void RunJobs()
{
this.mainLoop.RunJobs();
}
/// <summary>
/// Invokes a method on the dispatcher thread.
/// </summary>

54
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;
}
/// <summary>
/// Runs continuations pushed on the loop.
/// </summary>
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;
}
}

11
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;
}

Loading…
Cancel
Save