Reputation: 633
I'm currently developping a small application based on a Master Detail template. One of my Pages
requires some data to be loaded immediatly, and I dont know how to do this. In every example, data is loaded once user press a button.
Here is my current code :
string test = async (sender, e) => {
Task<string> json = GetRandomRelations ();
return await json;
};
And my method
public async Task<string> GetRandomRelations () {
var client = new System.Net.Http.HttpClient ();
client.BaseAddress = new Uri("http://127.0.0.1/loltools/web/app_dev.php/api/relation/");
string response = await client.GetStringAsync("random/20");
return response;
}
I'm currently just trying to get the json response, but I cannot even manage to do that... My main problem is that I cannot convert the lambda expression to string...
Thanks for your help !
Upvotes: 2
Views: 5194
Reputation: 457402
One of my Pages requires some data to be loaded immediatly, and I dont know how to do this.
Think about this for a bit. What you're really asking is how to reconcile two opposing requirements:
So, obviously, there's no direct solution. Instead, you have to satisfy the both of the core requirements ("The UI must be responsive" and "The data is retrieved asynchronously") in a different way. One common approach is to (immediately and synchronously) display a "Loading..." view of the data - a spinner or whatnot. Then, update the display when the data arrives.
Upvotes: 1
Reputation:
I'm not absolutely sure what you are trying to do but what's wrong with simply:
string test = await GetRandomRelations ();
Upvotes: 0