Stay organized with collections
Save and categorize content based on your preferences.
.NET timeouts
Functions Framework for .NET uses cancellation tokens to indicate when a function
times out.
You can retrieve the cancellation tokens based on how you implement your
functions:
For HTTP functions implementing the IHttpFunction interface, retrieve the
cancellation token from the
HttpContext.RequestAborted
property.
For event-driven functions implementing the ICloudEventFunction,
ICloudEventFunction<TData> or ITypedFunction<TRequest, TResponse>
interfaces, the cancellation token is passed into the HandleAsync method.
You use the cancellation token to handle a function timeout terminating the
request. Pass the cancellation token to any asynchronous methods you call so that
the function code aborts gracefully, rather than performing work that won't be
used.
If your function uses time-consuming synchronous code and there's no asynchronous
equivalent, periodically call the CancellationToken.ThrowIfCancellationRequested
method; for example, in every iteration of a synchronous loop.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-21 UTC."],[[[".NET Functions Framework uses cancellation tokens to signal function timeouts."],["HTTP functions get the cancellation token from the `HttpContext.RequestAborted` property."],["Event-driven functions receive the cancellation token through the `HandleAsync` method."],["Cancellation tokens should be passed to asynchronous methods to ensure graceful aborting."],["Synchronous code should periodically check for cancellation via `CancellationToken.ThrowIfCancellationRequested`."]]],[]]