Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,978 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have an azure function which has been called every 5minutes. The function takes less than a min to respond but sometimes took longer than normal and causes some logical issues in my app. How can I cancel the request if takes more than x min (e.g. 4min)?
var response = await client.GetStringAsync()
You have two choices:
client.Timeout = TimeSpan.FromMinutes(4);
try
{
var response = await client.GetStringAsync();
}
catch (TaskCanceledException)
{
// your logic when timeout happens
}
var cts = new CancellationTokenSource()
cts.CancelAfter(4 * 60 * 1000);
try
{
var response = await client.GetStringAsync(uri, cts.Token);
}
catch (TaskCanceledException)
{
// your logic when timeout happens
}