Carry out an activity for a limited time

I have a process in which I need it to do the while activity, for a period of time, for example 3 minutes. How could I do it?

@Marisa_Ontiveros1

before while start store the curenttime using DateTime.Now

and in the while condition give Now < StartTime.AddMinutes(3)

once 3minutes is crossed it would stop the loop

cheers

there are several techniques

  • stopwatch checks within the while loop confition check
  • controlled for each iteration with loop break