Question: I have a simple Android application I drafted which does mathematical calculations in a loop for a certain number of seconds (in this case 100). However, when I run the application, because nothing is done in the program until after the loop, when it writes the number of calculations completed, it shows as not responding. Is there a simple way I can fix this?

Answer: 
You must do it in another Thread, in this way the UI will not block and not become irresponsive.

Meanwhile you can show an activity indicator using a progress dialog. and when the process is done hide it.

Beware with UI operations in cross-threading.
Use async await and run the math in a task. If you start the task from an activity do not forget to cancel it if for some reason the activity gets destroyed.

Here is a quick sample that should get you started (alternatives commented out):

```
[Activity (Label = "AsyncSample", MainLauncher = true)]
public class MainActivity : Activity
{
    private CancellationTokenSource cancellation;
    private Button button;
    private Task task;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate (bundle);

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        button = FindViewById<Button> (Resource.Id.myButton);

        button.Enabled = false;
        this.cancellation = new CancellationTokenSource ();
        this.task = RunTask(this.cancellation.Token, new Progress<int> (a => this.button.Text = string.Format ("Progress {0}", a)));
    }

    protected override void OnDestroy()
    {
        this.cancellation.Cancel ();
        base.OnDestroy ();
    }

//        protected override void OnStop()
//        {
//            base.OnStop ();
//            this.cancellation.Cancel ();
//        }
//
//        protected override async void OnStart()
//        {
//            base.OnStart ();
//
//            this.cancellation = new CancellationTokenSource ();
//            await RunTask (this.cancellation.Token, new Progress<int> (a => this.button.Text = string.Format ("Progress {0}", a)));
//        }

    private Task RunTask(CancellationToken cancelToken, IProgress<int> progress)
    {
        return Task.Factory.StartNew(()=>
        {
            for (var n = 0; n < 100 && !cancelToken.IsCancellationRequested;)
            {
//                    await Task.Delay (1000);
                Thread.Sleep(1000);
                progress.Report (++n);
            }
        });
    }
}

```