Search code examples
c#backgroundworkerdotnet-httpclientmultitasking

TaskCanceledException after 100 seconds


I use a backgroundworker in my asp.net core web-service. In this backgroundworker I use:

var response = await client.PostAsync(baseUri + "/api/worker/" + Id , content);

This works fine if the call takes less than 100 seconds, but if it takes longer, then it thows a TaskCanceldException.

So how can I increase this timeout?


Solution

  • If the client var is HttpClient, you can set its Timeout property.

    HttpClient httpClient = new HttpClient();
    httpClient.Timeout = TimeSpan.FromMinutes(10);
    

    Here is the official doc