Xamarin multi-threading/ui



  • Hi

    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 http://docs.xamarin.com/Android/Guides/Advanced_Topics/Writing_Responsive_Applications 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?



  • 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.


Log in to reply