相关疑难解决方法(0)

使用带有 Http 触发器的取消令牌的 Azure 函数

我正在使用取消令牌在 Azure 中开发一个函数。它是一个 Http 触发器。

我在方法参数中传入了一个取消令牌。

其长运行功能。我在进程之间取消了请求,但进程继续运行并且取消令牌不生效。

这在 Azure Functions 中是否支持,如果我在两者之间取消 Http 请求,它也应该取消其执行,但事实并非如此。

我通过一小段代码对此进行了测试

public static class LongRunningFunction
    {
        [FunctionName("LongRunningFunction")]
        public static async Task<IActionResult> RunAsync(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post",  Route = "Long")]
            HttpRequest req, ILogger log, CancellationToken token)
        {
            try
            {
                await Task.Delay(10000, token);
                return new OkResult();

            }
            catch (OperationCanceledException)
            {
                return new NotFoundResult();
            }
            catch (Exception e)
            {
                return new InternalServerErrorResult();
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我使用 Postman 执行。

难道我做错了什么?

我正在从以下链接获取帮助

c# multithreading azure cancellation-token azure-functions

9
推荐指数
2
解决办法
3415
查看次数