Lunar
❔ HttpClient Error
try
{
CancellationTokenSource timeoutSource = null;
if (x)
{
//For A request
timeoutSource = new CancellationTokenSource(TimeSpan.FromSeconds(3));
}
else if(y)
{
//For B request
timeoutSource = new CancellationTokenSource(TimeSpan.FromSeconds(5));
}
//Reset request will default
var result = await client.GetAsync(url, timeoutSource.Token);
}catch()
107 replies
❔ HttpClient Error
Then I can remove Timeout from HttpClientObject and student and then add this condition
if(A)
{
CancellationTokenSource timeoutSource = new CancellationTokenSource(2000);
var result = client .GetAsync("url",timeoutSource.Token).GetAwaiter().GetResult();
} else{
CancellationTokenSource timeoutSource = new CancellationTokenSource(default);
var result = client .GetAsync("url",timeoutSource.Token).GetAwaiter().GetResult();
}
}
107 replies
❔ HttpClient Error
like this ?
CancellationTokenSource timeoutSource = new CancellationTokenSource(2000);
await httpClient.GetAsync("http://www.foo.bar", timeoutSource.Token);
107 replies