MethodInvokerのキューを作成します
Queue<MethodInvoker> EventCall = new Queue<MethodInvoker>();
後でアイテムをキューに追加します
EventCall.Enqueue(ClearAllVals);
EventCall.Enqueue(saystuff);
EventCall.Enqueue(testFunc);
次に、関数を一度に1つずつ呼び出します。
MethodInvoker bb = EventCall.Dequeue();
bb();
bb = EventCall.Dequeue();
bb();
bb = EventCall.Dequeue();
bb();
すべての関数を安全な方法で呼び出すため(これにより、キューからすべての関数が削除され、キューが空になり、すべての関数が呼び出されます)
public bool InvokeAll(){
MethodInvoker bb = null; // this will hold the function prior to use
for(int i = 0; i<EventCall.count; i++){
bb = EventCall.Dequeue(); //pull a method off of the queue
bb(); //call the method you pulled off of the queue
}
}
それらすべてを呼び出すには、使用するInvokeAll();
か、必要なときに一度に1つずつ呼び出します。
public bool NextEvent(){
MethodInvoker bb = null; // this will hold the function prior to use
if(EventCall.count > 0){
bb = EventCall.Dequeue(); //pull a method off of the queue
bb(); //call the method you pulled off of the queue
} else {
MessageBox.Show("there was no event to call"); // this is optional, point being you should be handeling the fact that there is no events left in some way.
}
}