What is the best way to repeat a code activity every 2 minutes until a certain condition is met?
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. Should I just use Timer.Sleep in the code or is that bad practice?
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: