public static void ShowLoadingHUD(this UIView view, string title, Action <IProgressDelegate> action) { bool isCompleted = false; Exception error = null; // view.InvokeOnMainThread( // () => { var hudView = new LoadingHUDView(title, "processing"); var hudFrame = hudView.Frame; hudFrame.Height += (float)(view.Window.Frame.GetMidY()); hudView.Frame = hudFrame; view.Window.Add(hudView); hudView.StartAnimating(); Tools.Threads.QueueAction( () => { try { action(new ActionProgressDelegate((msg) => view.InvokeOnMainThread(() => hudView.Message = msg))); } catch (Exception actionError) { error = actionError; } finally { view.InvokeOnMainThread( () => { try { hudView.StopAnimating(); hudView.RemoveFromSuperview(); } catch { // ignore errors here } finally { isCompleted = true; } } ); isCompleted = true; } } ); // }); while (!isCompleted) { NSRunLoop.Current.RunUntil(NSDate.FromTimeIntervalSinceNow(0.2)); } if (error != null) { SystemLog.Exception(error); throw new SoftwareException(error, "An unexpected error occured in an asyncronous task"); } }
void HandleButtonTouchUpInside(object sender, EventArgs e) { _hud.StartAnimating(); NSTimer.CreateScheduledTimer(TimeSpan.FromSeconds(5), (timer) => _hud.StopAnimating()); }