【发布时间】:2021-10-27 02:33:02
【问题描述】:
我想限制天蓝色函数的执行时间,并在其上添加了TimeoutAttribute,如下代码。
[FunctionName("Func2")]
[Timeout("00:00:02", TimeoutWhileDebugging = true)]
public static void Run([TimerTrigger("*/5 * * * * *")] TimerInfo myTimer, ILogger log)
{
log.LogInformation($"hi...");
int length = 10;
for (int i = 0; i < length; i++)
{
log.LogInformation($"looping {i + 1}...");
//System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
System.Threading.Tasks.Task.Delay(3000).Wait();
}
}
我在本地的 Visual Studio 2019 中运行了代码。我预计上面的代码会在 2 秒内超时,但它运行了完整的 10 个循环,没有任何错误。
上面有什么问题吗?
【问题讨论】:
标签: c# .net azure azure-functions