c# - Make Async Rest Request -
I am using RestSharp to request some rest on Windows Phone.
But I am struggling to use
private zero function () {var client = new RestSharp.RestClient ("https://exampleapi.com" ); Client.Authenticator = [....] var request = new RestSharp.RestRequest ("/ example.json", method GET); {Client.ExecuteAsync (Request, reponse => {{reponse.StatusCode ==} HttpStatusCode.OK) {// Operation with json ...} and {MessageBox.Show ("Error");}}) Do; } Hold (exception error) {MessageBox.Show (error.Message); }
I tried to add the term async
:
private async zero restsharptest () {var client = New RestSharp.RestClient ("https://exampleapi.com"); Client.Authenticator = [....] var request = new RestSharp.RestRequest ("/ example.json", method GET); {Client.ExecuteAsync (request, reponse = & gt; {(reponse.StatusCode == HttpStatusCode.OK} {var timeline = JsonConvert.DeserializeObject & lt; list & lt; dynamic & gt; & gt; (reponse.Content); } And {Message Box ("Error");}}); } Hold (exception error) {MessageBox.Show (error.Message); }}
But try adding when I try:
var timeline = wait JsonConvert.DeserializeObject & lt; List & gt; Dynamic & gt; & Gt; (Reponse.Content);
I get the following errors:
'system.clalls. Impossible to reach the generic .list
and:
The operator 'wait' can only be used in Lambda expression asynchronously, this lambda expression correction Mark as 'async'.
How can I use my code "async / await ?
Edit:
client.ExecuteAsync (request, response => {(response.StatusCode == HttpStatusCode.OK) {List_ = New list & lt; Myobject & gt; (); List_ = await work.factory. New (() = & gt; JsonConvert.DeserializeObject & lt; list & lt; Myobject & gt; & gt; (response.Content); tcs.SetResult (RefreshList_);} and {MessageBox.Show ("Error");}});
I have this error again:
The operator 'wait' can only be used in lambda expression async, it is called lambda expression correctional async Mark with '.
How do I solve it?
Comments
Post a Comment