protected virtual bool InternalRun() { RunningThread = this; bool isDone = true; while (mContextStack.Count > 0) { IEnumerator top = mContextStack.Peek(); #if DEBUG try { #endif while (isDone = !top.MoveNext()) { //If one stack frame done, we will try to make it run ContextStackPop(); if (mContextStack.Count > 0) { top = mContextStack.Peek(); } else { break; } } #if DEBUG } catch (Exception e) { throw new StThreadException(e, CallStack); } #endif if (mContextStack.Count > 0 && top.Current != null) { #if DEBUG Debug.Assert(((IEnumerator)top.Current).Current == null, "New Stack Frame run before push To Context Stack."); #endif ContextStackPush((IEnumerator)top.Current); //Force run again to avoid yield return CallFunction one frame delay problem. continue; } break; } RunningThread = null; return(isDone); }
public void AddChildThread(StThread child, IEnumerator context) { mChildThread.Add(child); mChildContext.Add(child.RunThread(context)); }