It would be better to have something derived from AlertView (a loading dialog), unless you want to perform background loading.
This then runs the task in a separate Thread
which you Join and then close the dialog. There's an example here, but doesn't feature any threading however it's trivial to add:
public class LoadingView : UIAlertView
{
private UIActivityIndicatorView _activityView;
public void Show(string title)
{
Title = title;
Show();
// Spinner - add after Show() or we have no Bounds.
_activityView = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge);
_activityView.Frame = new RectangleF((Bounds.Width / 2) - 15, Bounds.Height - 50, 30, 30);
_activityView.StartAnimating();
AddSubview(_activityView);
// I haven't tested this, it should display the dialog still.
Thread thread = new Thread(DoWork);
thread.Start();
thread.Join();
Hide();
}
private void DoWork()
{
PlanDomain domain = PlanDomain.Instance ();
while (domain.IsLoadingData)
{
// Maybe replace domain.IsLoadingData with an Event for when it finishes.
// And then use a Mutex (WaitHandle) to communicate back
}
}
public void Hide()
{
DismissWithClickedButtonIndex(0, true);
}
}