I have a method in a WPF client for a Web API:
public async Task PostFileAsync(string localPath, string serverPath)
The meat of this method is the call:
var resp = await _client.PostAsync(uri, content);
where _client
is an HttpClient
instance.
When I try uploading large files that apparently take too long, I get an A task was canceled.
exception, with the following stack trace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at QuickDrive.Wpf.Api.ApiClient.<PostFileAsync>d__10.MoveNext() in C:\Projects\QuickDrive\Code\QuickDrive.Wpf\Api\ApiClient.cs:line 176
I see no mention of any timeout here, but this task completes nicely for posts that take less than about 10 minutes (I haven't timed it exactly), e.g. on my connection for files smaller than +-500MB.
Is this exception really because of a timeout, and if so, how can I configure the await
to allow for a configurable time before canceling the task; assuming the task is canceled because of a timeout. It never gets canceled for any other scenario than when I try and upload a large file.