How can i compare the consecutive results of a method return value is smae or not inside while loop(infinite)

  • Thread starter Thread starter La07K
  • Start date Start date
L

La07K

Guest
Hi i am executing a function in an infinite while loop for some particular timeout.

here my requirement is if my method return two times same output then i have to return from the loop.

Below is my code snippet,here i am using one list then checking the consecutive values are equal or nt(true).But is there any alternative better performing way is there or not?


pleae give ur inputs.

private StatusInfo WaitforState(State state, TimeSpan timeout)
{
List<bool> resultList = new List<bool>();
while (true)
{
Thread.Sleep(10000);
var t = timeout.Subtract(new TimeSpan(0, 0, 10));

if (t == TimeSpan.Zero)
break;

var r = GetStatus();

if (null == r)
continue;

if (r.State == state)
{


if (state == State.Open && r.Mode == StateMode.Enter)
{
resultList.Add(true);

if (resultList.Count >= 2)
{
for (int i = 0; i < resultList.Count-1; i++)
{
// If consecutive elements are same with 10s interval then will confirm done with ok
if (resultList&& resultList[i + 1])
return StatusInfo.OK;
}
}
}
else
{
resultList.Add(false);
}

}
}

return StatusInfo.Error;
}




Coding.....................................

Continue reading...
 
Back
Top