Skip to content

Instantly share code, notes, and snippets.

@koush
Created August 20, 2010 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koush/539485 to your computer and use it in GitHub Desktop.
Save koush/539485 to your computer and use it in GitHub Desktop.
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.Threading;
namespace HelloDroid
{
public class Activity1 : Activity, Java.Lang.IRunnable
{
int count = 1;
Android.OS.Handler mHandler = new Handler();
public Activity1(IntPtr handle)
: base(handle)
{
}
Button button;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Create your application here
button = new Button(this);
button.Text = "Click Me!";
button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
SetContentView(button);
byte[] stuff = new byte[200];
var thread = new Thread(() =>
{
byte[] foo = new byte[94934];
Thread.Sleep(2000);
// this will cause an activity not responding. the gc's call to pthread_kill fails with EPERM
// and deadlocks the app.
System.GC.Collect();
mHandler.Post(this);
}
);
thread.Start();
}
public void Run()
{
button.Text = "thread done!";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment