member _.InvokeOnUiThread(func: Func<Task<'a>>): Task<'a> =
if Application.Current.Dispatcher.CheckAccess() then
func.Invoke()
else
let tcs = new TaskCompletionSource<'a>()
let d =
Action(fun () ->
async {
let! result = func.Invoke() |> Async.AwaitTask |> Async.Catch
match result with
| Choice1Of2 r -> tcs.TrySetResult(r) |> ignore
| Choice2Of2 ex -> tcs.TrySetException(ex) |> ignore