asynchronous - Xamarin Android F# update UI in async block -
i'm new xamarin, , trying build simple android app f#. i'm trying load in data rest api async, , display it. understand interacting ui must done on mainthread, , there along lines of activity.runonuithread()
. i've tried following:
let onsearch args = let search = this.findviewbyid<edittext>(resource_id.search) let searchresults = this.findviewbyid<textview>(resource_id.searchresults) button.text <- search.text async { let! results = recipesearch.getrecipes search.text searchresults.text <- results } |> async.start button.click.add onsearch
which throws exception interacting ui elements in thread. , this:
let result = async { let! results = recipesearch.getrecipes search.text return results } |> async.runsynchronously searchresults.text <- result
defeats purpose of doing async
thanks
try this:
let onsearch args = let search = this.findviewbyid<edittext>(resource_id.search) let searchresults = this.findviewbyid<textview>(resource_id.searchresults) button.text <- search.text async { let! results = recipesearch.getrecipes search.text this.runonuithread(fun () -> searchresults.text <- results) } |> async.start button.click.add onsearch
Comments
Post a Comment