3
我試圖使用HttpClient的使用下面的代碼以異步日誌消息REST服務:HttpClient的任務被取消
public void LogMessage(string operationURI, string message, EventLogEntryType logEntryType)
{
using (var client = new HttpClient())
{
var cancellationToken = new CancellationToken();
client.SendAsync(GetRequest(operationURI), cancellationToken).ContinueWith(
cw =>
{
var response = cw.Result; //(I get an error on this line)
if (!response.IsSuccessStatusCode)
{
LogMessageLocal(message, logEntryType);
}
});
}
}
注:GetRequestMessage返回HttpRequestMessage。
但是我收到一個錯誤,指出'任務被取消。'
任何想法?