[mono-android] Why do I NOT need RunOnUIThread?
Wally McClure
theevilprogrammer at hotmail.com
Tue Jan 3 13:52:15 EST 2012
I've been working on this simple use of the Progress Dialog. I have everything working, and then it hit me that I am not using RunOnUIThread. My code is below. I put in RunOnUIThread in several places and it still works as I would think it would. Is there something magical about the Progress Dialog not needing the RunOnUIThread to be sprinkled in?
ProgressDialog progressDialog;
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 button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate {
progressDialog = new ProgressDialog(this);
progressDialog.SetProgressStyle(ProgressDialogStyle.Horizontal);
progressDialog.SetMessage("Loading...");
progressDialog.SetCancelable(true);
progressDialog.Show();
System.Threading.ThreadPool.QueueUserWorkItem(
new System.Threading.WaitCallback(ProgressProcess));
};
}
private void ProgressProcess(object state)
{
while (progressDialog.Progress < 100)
{
RunOnUiThread(delegate{
progressDialog.IncrementProgressBy(1);
});
System.Threading.Thread.Sleep(50);
}
RunOnUiThread(delegate
{
progressDialog.Dismiss();
});
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monodroid/attachments/20120103/c5d9bed2/attachment-0001.html
More information about the Monodroid
mailing list