Time a process flow and act when time is exceeded

Is it possible to build in some kind of timer that starts when a transaction item is picked up and that acts when a certain amount of time has passed? Then timer then resets when the next item is picked up.

Thx for your insights.

1 Like

You just need to have a timespan variable and a variable to store the current time to when you pick up the item. Then, you can basically do
(Now - startTime) >= timespan
as a condition, then perform your actions and reset startTime to Now before getting next item again.

timespan could be set to something like 00:05:00, for 5 minutes
startTime would be a DateTime type

I hope I have clear.



The idea would be to send an email to the developer when the time has exceeded, because these tasks are sequential would it the be possible to stop the email from being sent if the time hasn’t exceeded its value?

Yeah, like I said you can use a condition like this:

if (Now - startTime) <= timespan


if (Now - startTime) <= 01:00:00

Send the email in the True side, and in the False side do something else.

Initialize startTime = Now as a dateTime variable type, and assign that right after you get each item to store the initial time.




Could I limit a workflow to be executed in a certain period of time (let’s say 1 minute), and if it is not executed in <=1minute, do a certain action?

I mean if it takes more than a minute to execute all the activities contained in a workflow, I want to do some actions such as sending an email.

Thanks a lot.



Hey, there are 2 ways to do this I think.

Orchestrator has a feature (if it is a scheduled job) where you can have it “Stop or Kill After” a certain amount of time. If you have it set to “Stop After”, it will trigger its “Should Stop”. So when your workflow hits the “ShouldStop” activity, you can use that boolean in a decision and perform other actions - also if you Manually choose to “Stop” the process in Orchestrator. You might also be able to use this in a Parallel activity (to stop at anytime rather than inbetween items processed), though I would suggest having your shouldstop then in a separate workflow or library to invoke so it can continue to wait for ShouldStop in a loop, if you choose this approach.

The other way is to basically do the same thing in parallel, but instead of waiting for the ShouldStop to be True, you instead calculate the timespan and compare it in a decision to decide to perform those actions. - and like I said, you can do this inbetween items processed too instead of in parallel.

So maybe those are some ideas.

@ ClaytonM

Thank you very very much Clayton.

It would work if the whole process would take 1 minute to be executed. However, it takes 1 minute to process every operation of my process (my process consists of a huge amount of operations).

So what I would need is to establish a limit period of time so that each operation that lasts more than 1 minute, can be cancelled and then the following operation is executed.


I see, so you would probably prefer the approach of calculating the timespan in the code. Surround each iteration with a parrallel activity, and in parallel invoke a workflow that determines if the timespan has exceeded in a Do While loop, that also checks if the iteration is complete (maybe by some boolean variable) - so it can exit the Do While to go to the next iteration… if that makes sense. If the timespan is met, then you would Throw an exception so it can jump out of the iteration being processed so it can go to the next iteration.

—If you give it a shot, let me know if you have other questions further on how to compose this logic. Regards.

Hi @pal1910

I felt like a sample might make you understand better, so I quickly put this together.
Main.xaml (14.5 KB)

So basically it loops through to process each iteration with a Parallel surrounding the process. After each activity, it will check the timespan and throw a businessruleexception if it is exceeded. Keep in mind, that this only works if an activity does not get stuck with no timeout.

I placed in a Delay to test this, so after the Delay ends, it throws the exception to move to next iteration.

You’ll need to make adjustments to meet your requirements.

I hope this helps better.



Thanks a lot.

That’s a perfect solution for me!

Best regards

Hey Clayton, thanks for the solution, however, when I tried implementing the same, my process fails with a delay activity in the workflow!

Hi @ClaytonM, I appreciate your idea and found some interest issues as below.
Reference: Using the ParallelActivity Activity | Microsoft Learn

  1. When Delay in Task 2 is set to 2 seconds and maxIterationTime is set to 10 seconds, it seems the activity doesn’t switch back to first SequenceActivity after the Delay activity. All 5 objects go to the Exception.
  2. Same scenario as point1 but add a 1s delay, result is same as point1.
  3. Same scenario as point1 but add a 2s delay, result is expected as no Exceptions.

Refer to above reference, activities should be switched between SequenceActivities even faces DelayActivity. Any ideas? Thank you.

I’m unsure how your code looks exactly. Keep in mind that [ Now-iterationStart ] in the right side of the parallel is based on total difference in time when you assigned ‘iterationStart’, so ensure this is assigned in the correct place at the start of the iteration process.

It might help you to Log (Now-iterationStart).ToString at some places, so you know when and where it is in the process and if it should hit the exception at that moment or not.

I might also suggest that the IF condition be changed to:
Not iterationComplete AndAlso Now - iterationStart >= maxIterationTime
so it doesn’t accidentally throw exception at the end if the iteration was complete