2

可以在这样的 Azure 持久功能活动中使用 Task.Delay吗?

我正在轮询应该在 20-30 秒左右到达的数据的存储。

 while (requestAccepted && retryCount < 8)
        {
            object savedData = await DataManagementService.GetSessionData(processSessionId);

            if (savedData != null && savedData.GetType().GetProperties().Any())
            {
                return true;
            }

            await Task.Delay(TimeSpan.FromSeconds(10));

            retryCount++;
        }

此处context.CreateTimer解释的功能计时器功能仅适用于 Azure编排功能,不适用于活动功能。

4

1 回答 1

2

Task.Delay()只要您愿意为函数等待时的死时间付出代价,并且您知道它会在超时之前完成,那么使用它是完全可以的。

但是,更好的选择是将GetSessionData()调用移动到一个活动函数中,将此轮询函数转换为一个编排器,以便您可以替换Task.Delay()context.CreateTimer()并通过主编排器调用它context.CallSubOrchestratorAsync()

于 2019-05-14T14:16:19.860 回答