I am trying to use HttpClient to asynchronously log a message to a REST service using the code below:
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);
}
});
}
}
Note: The GetRequestMessage returns an HttpRequestMessage.
But I get an error stating 'A task was canceled.'
Any ideas?
I believe this can occur when the timeout is exceeded. You might check your timeout, and log how long it was outstanding before the exception to see if it is being exceeded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With