![](/img/trans.png)
[英]How should I implement ExecuteAsync with RestSharp on Windows Phone 7?
[英]How to implement call to call ExecuteAsync using RestSharp
我試圖使用RESTSharp調用REST服務並立即繼續執行,因為我只需要啟動一個任務,但需要立即繼續執行,所以我嘗試使用ExecuteAsync而不是Execute。
我的代碼現在應該像這樣
IRestResponse<ExpandoObject> restResponse = client.ExecuteAsync<ExpandoObject>(restRequest, response =>
{
callback(response.Content);
});
但是,我不知道如何實現回調函數,並且所有示例都沒有顯示它。 我以為是這樣,但無法編譯。
private IRestResponse<ExpandoObject> callback(string content)
{
return null;
}
有任何想法嗎?
有幾種方法可以實現您要執行的操作,但是您的回調似乎具有錯誤的方法簽名...要使“基本”運行,以下應能工作(我添加了等待測試的內容):
EventWaitHandle resetEvent = new AutoResetEvent(false);
client.ExecuteAsync(request, response =>
{
callback(response.Content);
resetEvent.Set();
return;
});
resetEvent.WaitOne();
}
private static void callback(string content)
{
System.Console.WriteLine(content);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.