Not able to stop while loop

Hi,

I have a while loop which will be executing for 3 minutes. I have 3 elements to be checked and if neither of the elements are found, then the while loop will exit throwing a exception. Below is my code. While loop is not getting stopped after 3 min. Someone please check and let me know what wrong i have made

Main.xaml (16.1 KB)

can anyone pls help me on above issue

@Sirisha_Siri could you please share the snapshot of while loop??


It is behaving as infinite loop. I need to stop loop after one hr[if none of the elements found] or whenevr one of the three elements are found. For testing purpose i gave 3 min and checked.

@Sirisha_Siri Have you converted the time into DateAndTime format?

image
i assigned like this for time variable

These are strings, you need to compare datetime variables, not strings

could you please let me know how to compare datetime variables

@Sirisha_Siri could you please explain in details what’s your process extract does?

What is your condition for while loop and what are the condition you are comparing through the if conditions ?

@Sirisha_Siri change the type of your variable time to “System.DateTime”, comparison will be like:
Datetime.now.addMinutes(6) < time (Dont use .ToString to make it string)

my while loop has to execute for 6 minutes. I need to give condition in while loop to compare current time with time after 6 minutes. while loop will check 3 elements using element exists activity. if neither of the elements found within 6 minutes, it has to come out of the loop. But in my code loop is executing continously irrespective of time

You can’t use a condition like that. It’s recalculated every time the While loops. So it’ll never be false.

how to get this solved?

i have used assign activity and assigned time before while loop. even though condition is not becoming false. while loop is getting executed continously. Please help @postwick

Hello @Sirisha_Siri

So in that 6 minutes , is your process perform some other actions or just keeps on looping??

If that is the case you can use a delay activity and get the value to another variable and then use a if condition to compare the dates insitead of a loop.

you this in while condition

DateTime.now<=convert.ToDateTime(time)

Assign startTime = Now

Do While DateDiff(DateInterval.Minute,startTime,Now) < 6

annother approach:

  • Create a boolean variable for your condition and make it false
  • Add your while loop to a Parallel activity on the left side
  • Make your loop condition to execute while not YourVariableName
  • On the right side Parallel activity add a sequence with a 6 min delay activity and make your boolean true right below the delay
  • loop will stop after the assign is executed

He doesn’t want a X minute delay. He wants it to loop for X minutes, repeatedly checking for the elements.

And in your scenario there’s no reason for Parallel. Parallel doesn’t execute activities at the same time. The Do While would execute, then the delay, then the assign.