Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DeviceThreadDispatcher : IThreadDispatcher
- {
- private static int _uiThreadId;
- public bool IsOnUiThread => Environment.CurrentManagedThreadId == _uiThreadId;
- public static void Initialize(int uiThreadId) => _uiThreadId = uiThreadId;
- public T RequestMainThreadAsyncOperation<T>(Func<Task<T>> operation)
- {
- var result = default(T);
- var taskCompletionSource = new TaskCompletionSource<bool>();
- Device.BeginInvokeOnMainThread(async () =>
- {
- result = await operation();
- taskCompletionSource.SetResult(true);
- });
- if (taskCompletionSource.Task.Result)
- {
- return result;
- }
- return default (T);
- }
- }
Add Comment
Please, Sign In to add comment