The Daily WTF: Curious Perversions in Information Technology
in Search

Xamarin multi-threading/ui

Last post 11-19-2012 11:23 AM by PSWorx. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 11-13-2012 7:00 PM

    Xamarin multi-threading/ui


    I'm currently trying to build an app for android in Xamarin. It's C pound made to run on android/ios, it's useful because we have some fairly advanced algorithms that we'd rather not have to test/implement several times.

    Now to the question:
    I'm trying to retrieve some data with a WebRequest, and i'd like to do so asynchronously, for obvious reasons. Xamarin suggests using RunOnUiThread() when reporting back to the UI which seems like an ugly hack at best (what if i have two async threads running, and they try to modify the same UI element ?, what if i have changed context/tab/whatever in the mean time ?, how the HELL do i keep track of my app's state ?). Is this really the right approach, or am i missing something completely obvious?

  • 11-19-2012 11:23 AM In reply to

    Re: Xamarin multi-threading/ui

    I'm not familiar with Xamarin (or the perks of Android development), but this looks like the usual design pattern for doing responsive UI. The RunOnUiThread() method exists exactly to solve your "multiple async workers" problem - It'll put each worker's callback in the UI thread's event queue and run them (in arbitrary order) as soon as all pending UI events have been processed.
Page 1 of 1 (2 items)