Saxonite 1.2.11.3. Sandtrap.

This commit is contained in:
Andy Howard
2024-04-24 17:18:05 +01:00
parent 496aaeee0b
commit 7748941680
104 changed files with 5615 additions and 177 deletions
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Sarand.Net.Mobile.Xamarin.Tasks
{
//=======================================================================
public static class SaxThreadUtil
{
//-------------------------------------------------------------------
// I n v o k e o n M a i n T h r e a d a n d W a i t
//-------------------------------------------------------------------
// Invoke task on main thread and wait for completion.
public static void BeginInvokeOnMainThreadSync (Action taskFn)
{
var tcs = new TaskCompletionSource<Object>();
Device.BeginInvokeOnMainThread(() =>
{
try
{
taskFn();
tcs.SetResult(null);
}
catch (Exception ex) { tcs.SetException(ex); }
});
}
public static T BeginInvokeOnMainThreadSync<T> (Func<T> taskFn)
{
var tcs = new TaskCompletionSource<T>();
Device.BeginInvokeOnMainThread(() =>
{
try
{
var result = taskFn();
tcs.SetResult(result);
}
catch (Exception ex) { tcs.SetException(ex); }
});
return tcs.Task.Result;
}
//-------------------------------------------------------------------
}
//=======================================================================
}