Search code examples
c#xamarinxamarin.formstimeoutdotnet-httpclient

Suddenly can't change timeout on HttpClient


I have the following code temporarily changing the timeout on a singleton HttpClient...

Task IncreaseTimeout(Func<Task> action)
{
    var initialTimeout = Client.HttpClient.Timeout;

    try
    {
        Client.HttpClient.Timeout = new TimeSpan(0, 5, 0);

        return action();
    }
    finally
    {
        Client.HttpClient.Timeout = initialTimeout;
    }
}

It works fine on iOS and on Android until now, when it gives the following error when the Timeout property is updated...

This instance has already started one or more requests. Properties can only be modified before sending the first request.

Why has this started happening now and on only one platform?


Solution

  • Looks like this new Android behavior I'm having is actually correct. So I have set my default to one minute instead of thirty seconds and I will hope for the best when uploading files.