I am working with an object that needs to run an ExecuteEffect() method. Sometimes, the ExecuteEffect() only needs to run once, while in other cases, the ExecuteEffect() needs to keep running once / frame until some criteria is met (in my example, a real-time delay).To solve this, I used an IEnumerator:public override IEnumerator<bool> ExecuteEffect()    {        if(delay > 0)        {            if(executionStart == -1m)            {                executionStart = GetRealTime();                yield return false;            }            if(GetRealTime() > executionStart + delay)            {                DealDamage();                yield return true;            }            else            {                yield return false;            }        }        else        {            DealDamage();            yield return true;        }  }Then, when I'm running ExecuteEffect(), if the IEnumerator<bool> returns false, it gets added to a list of objects that is continuously checked until their ExecuteEffect() method returns true.GenericEffect ge = GetEffect();IEnumerator<bool> temp = ge.ExecuteEffect();temp.MoveNext();if(!temp.Current){    //Foo not finished, add to list of active Foo    activeEffects.Add(ge);}and, elsewhere:activeEffects.RemoveAll( s =>                         {                               IEnumerator<bool> temp = s.ExecuteEffect();                               temp.MoveNext();                               if(temp.Current)                               {                                   return true;                               }                               else                               {                                  return false;                               }                          });This all feels very wordy, especially the temp variable to hold the IEnumerator<bool> and the explicit call to GetNext(). And, of course, I have no idea if this is an utter butchering of the intended uses of IEnumerator<T>.Is there a better way to get this kind of effect? Or is this just an unconventional (albeit valid) use of IEnumerator<T>?
Using an IEnumerator without a foreach loop in order to simulate a state machine
c#;iterator
You could make life slightly easier for yourself by using the iterator slightly more properly:public override IEnumerator<bool> ExecuteEffect(){    if(delay < 0 || GetRealTime() > executionStart + delay)    {        DealDamage();        yield break;    }    if(executionStart == -1m)    {        executionStart = GetRealTime();    }    yield return false;}Then you could actually use MoveNext 'correctly' as it will return false when you get to the end.To be completely and brutally honest, I'd still rage erase all of this code if I found it in a project I worked on. Why is it an enumerator of booleans? None of it's particularly obvious.As an aside:if(temp.Current){    return true;}else{    return false;}is 100% the same asreturn temp.Current;