简体   繁体   English

Windows Workflow Foundation每隔X分钟重复一次活动

[英]Windows Workflow Foundation Repeat an Activity Every X minutes

What is the best way to repeat a code activity every 2 minutes until a certain condition is met? 在满足特定条件之前,每2分钟重复一次代码活动的最佳方法是什么?

Say I have the following code activity that checks a database to see that a batch of reports has been completed. 假设我有以下代码活动来检查数据库以查看是否已完成一批报告。

public sealed class CheckReportsAreComplete : CodeActivity
{        
    public InArgument<int> ReportBatchId{ get; set; }       
    public OutArgument<bool> HaveReportsCompleted{ get; set; }

    protected override void Execute(CodeActivityContext context)
    {             
        bool haveCompleted = ReportService.HaveReportsCompleted((context.GetValue(this.ReportBatchId));

        HaveReportsCompleted.Set(context, haveCompleted);                       
    }
}

I need this code activity to run every 2 minutes and continue processing when the OutArgument HaveReportsCompleted has been set to true. 我需要此代码活动每2分钟运行一次,并在OutArgument HaveReportsCompleted设置为true时继续处理。 Should I just use Timer.Sleep in the code or is that bad practice? 我应该在代码中使用Timer.Sleep还是那种不好的做法?

I'd assume I'd need a combination of a while/do while with a delay and condition? 我假设我需要一段时间/做的同时有延迟和条件?

Heres the solution I came up with: 以下是我提出的解决方案:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM