2017-09-28 14:52:27 +03:00
|
|
|
|
using GLib;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
namespace Xamarin.Forms.Platform.GTK
|
|
|
|
|
{
|
2018-09-20 22:11:20 +03:00
|
|
|
|
public class GtkSynchronizationContext : SynchronizationContext
|
|
|
|
|
{
|
|
|
|
|
public override void Post(SendOrPostCallback d, object state)
|
|
|
|
|
{
|
2018-11-06 14:12:58 +03:00
|
|
|
|
Gtk.Application.Invoke((s, e) =>
|
2018-09-20 22:11:20 +03:00
|
|
|
|
{
|
|
|
|
|
d(state);
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-09-28 14:52:27 +03:00
|
|
|
|
|
2018-09-20 22:11:20 +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
|
|
|
|
|
2018-11-06 14:12:58 +03:00
|
|
|
|
Gtk.Application.Invoke((s, e) =>
|
2018-09-20 22:11:20 +03:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
d(state);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
exception = ex;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
evt.Set();
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-09-28 14:52:27 +03:00
|
|
|
|
|
2018-09-20 22:11:20 +03:00
|
|
|
|
evt.WaitOne();
|
2017-09-28 14:52:27 +03:00
|
|
|
|
|
2018-09-20 22:11:20 +03:00
|
|
|
|
if (exception != null)
|
|
|
|
|
throw exception;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|