© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
106 replies
Lunar

❔ HttpClient Error

I have class HttpClientObject that create object of HttpClient

public class HttpClientObject{

private readonly HttpClient client;

public HttpClientObject(CustomParameters parameter)
{
handler=new HttpClientHandler(){}
client = new HttpClient(handler) { Timeout=parameter.timeout };
}

public HttpClient GetClient()
{
return client;
}
}

I have another class to fetch data
public class student{

HttpClientObject httpClientObject {get;set;}

HttpClient client = httpClientObject .GetClient();


//For X condition true it will timeout period 1 else by default

if(x)
{
client .Timeout = TimeSpan.FromSeconds(1);
}

var result = client .GetAsync("url").GetAwaiter().GetResult();

}


But I am getting error - "This instance has already started one or more requests. Properties can only be modified".
Getting error because of changing the Timeout and throws InvalidOperationException .
Is there any safe solution ?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

HTTPClient
C#CC# / help
2y ago
Slow HttpClient responses
C#CC# / help
2y ago
Different HttpClient headers
C#CC# / help
2y ago
✅ HttpClient to Json
C#CC# / help
3y ago
Next page