Skip to content

Instantly share code, notes, and snippets.

@gshackles
Created February 21, 2012 00:37
Show Gist options
  • Save gshackles/1872574 to your computer and use it in GitHub Desktop.
Save gshackles/1872574 to your computer and use it in GitHub Desktop.
async sample
using System;
using System.Threading;
using System.Threading.Tasks;
using Android.App;
using Android.Widget;
using Android.OS;
namespace MonoAndroidApplication18
{
[Activity(Label = "MonoAndroidApplication18", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
var button = FindViewById<Button>(Resource.Id.MyButton);
button.Text = "Before task starts";
Task.Factory.StartNew(() =>
{
Thread.Sleep(5000);
RunOnUiThread(() =>
button.Text = "Task is complete");
});
button.Text = "After task starts";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment