예제 #1
0
        private void RunEnumerator(IEnumerator enumerator)
        {
            ThreadBase currentThread = ThreadBase.CurrentThread;

            do
            {
                if (enumerator.Current is Task)
                {
                    Task taskBase = (Task)enumerator.Current;
                    currentThread.DispatchAndWait(taskBase);
                }
                else
                {
                    if (!(enumerator.Current is SwitchTo))
                    {
                        continue;
                    }
                    SwitchTo switchTo = (SwitchTo)enumerator.Current;
                    if (switchTo.Target == SwitchTo.TargetType.Main && currentThread != null)
                    {
                        Task taskBase = Create((Action) delegate
                        {
                            if (enumerator.MoveNext() && !ShouldAbort)
                            {
                                RunEnumerator(enumerator);
                            }
                        });
                        currentThread.DispatchAndWait(taskBase);
                    }
                    else if (switchTo.Target == SwitchTo.TargetType.Thread && currentThread == null)
                    {
                        break;
                    }
                }
            }while (enumerator.MoveNext() && !ShouldAbort);
        }