メソッドとイベントを使用してIAction
インターフェースを作成できます。Execute
Completed
IAction
次に、 sとpopのキューを作成し、現在のアイテムのハンドラーにExecute
次のアイテムを作成できます。Completed
yield return
s 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();
...
}