I am trying to create a custom thread class, but when I call its functions it blocks my UI thread. What I mean is that when I press the button, it stays pressed until the task completes.
This is the Main Activity:
using Android.App;
using Android.Widget;
using Android.OS;
using Java.Lang;
namespace ThreadTest08 {
[Activity(Label = "ThreadTest08", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity {
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate {
MyThreadClass mtc = new MyThreadClass();
mtc.Start();
mtc.DoSomething();
};
}
}
}
And this is the class:
using Java.Lang;
namespace ThreadTest08 {
class MyThreadClass : Thread {
public void DoSomething() {
Thread.Sleep(3000);
}
}
}
Why is this happening? Thanks for reading.