maui-linux/Xamarin.Forms.Platform.GTK/GtkSynchronizationContext.cs

52 строки
847 B
C#
Исходник Обычный вид История

2017-09-28 14:52:27 +03:00
using GLib;
using System;
using System.Threading;
namespace Xamarin.Forms.Platform.GTK
{
public class GtkSynchronizationContext : SynchronizationContext
{
public override void Post(SendOrPostCallback d, object state)
{
Gtk.Application.Invoke((s, e) =>
{
d(state);
});
}
2017-09-28 14:52:27 +03:00
public override void Send(SendOrPostCallback d, object state)
{
if (System.Threading.Thread.CurrentThread.ManagedThreadId == FormsWindow.MainThreadID)
{
d(state);
}
else
{
var evt = new ManualResetEvent(false);
Exception exception = null;
2017-09-28 14:52:27 +03:00
Gtk.Application.Invoke((s, e) =>
{
try
{
d(state);
}
catch (Exception ex)
{
exception = ex;
}
finally
{
evt.Set();
}
});
2017-09-28 14:52:27 +03:00
evt.WaitOne();
2017-09-28 14:52:27 +03:00
if (exception != null)
throw exception;
}
}
}
}