public static void SelectContactAddress(Action<string, Exception> addressSelected) { var task = new AddressChooserTask(); task.Completed += (s, e) => addressSelected.ExecuteIfNotNull(e.Address, e.Error); task.Show(); }
/// <summary> /// Invokes the given action on a background thread /// </summary> /// <param name="work">An action executed without UI access</param> /// <param name="onCompleted">An action executed on the UI thread after work is completed</param> public static void RunWorker(Action work, Action onCompleted) { // Don't do anything if the work action is empty if (work == null) { return; } if (IsRunningOnUIThread) { // Spawn new thread only if UI is active ThreadPool.QueueUserWorkItem( workAction => { ((Action) workAction)(); InvokeAsync(onCompleted); }, work ); } else { // Otherwise, just execute in linear fashion work(); onCompleted.ExecuteIfNotNull(); } }