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

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -