Writing to the UI with MonoDroid using RunOnUIThread

Posted by Wallym on ASP.net Weblogs See other posts from ASP.net Weblogs or by Wallym
Published on Mon, 17 Jan 2011 11:00:00 GMT Indexed on 2011/01/17 11:54 UTC
Read the original article Hit count: 380

Filed under:
|
|

I've been pulling my hair out over the past day or so trying to update the UI in my test app.  I was having problem after problem.  I finally got down to my base problem.  I could not write out to my TextView.  WTF could be causing that?  I can write to my UI in other parts of my app.  This is pure craziness.  I thought long and hard and nothing was coming to me.  Wait, the light bulb went on.  I am in the wrong thread.  Great, how do I write in the correct thread?  MonoDroid supports the entire AsyncTask set of objects, but this seemed like overkill.  I was reading and came across RunOnUIThread().......Bing..........The lightbulb has been invented...BlueStar Airlines (oh wait, wrong context). Anyway, here is what I needed:

this.RunOnUiThread(() => TextViewControl.Text = "Hello World");

Enjoy!!!!!!!  Remember kiddies, running on the main ui for off device operations is bad, not as bad as crossing the streams bad, but bad as in trying to drive on a flat tire bad. It won't kill you, but it does keep you from getting anywhere.

© ASP.net Weblogs or respective owner

Related posts about .NET

Related posts about android