代码之家  ›  专栏  ›  技术社区  ›  Mark

Silverlight 4中的C#处理队列

  •  1
  • Mark  · 技术社区  · 15 年前

    我怎么能这样做?

    1 回复  |  直到 15 年前
        1
  •  2
  •   SLaks    15 年前

    你可以做一个 IAction Execute Completed 事件

    s和流行音乐 当前项的处理程序。

    您甚至可以创建一个迭代器方法 yield return s IAction MoveNext() 之后 IAction

    编辑 :例如:

    class ActionEnumerator : IAction {
        readonly IEnumerator<IAction> enumerator;
        public ActionEnumerator(IEnumerator<IAction> enumerator) {
            this.enumerator = enumerator;
        }
    
        public void Execute() {
            //If the enumerator gives us another action,
            //hook up its Completed event to continue the
            //the chain, then execute it.
            if (enumerator.MoveNext()) {
                enumerator.Current.Completed += delegate { Execute(); };
                enumerator.Current.Execute();
            } else     //If the enumerator didn't give us another action, we're finished.
                OnCompleted();
        }
    }
    
    IEnumerator<IAction> SomeMethod() { 
        ...
        yield return new SomeAction();
        //This will only run after SomeAction finishes
        ...
        yield return new OtherAction();
        ...
    }