Saxonite 1.2.11.3. Sandtrap.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user