创建的MethodInvoker的
Queue<MethodInvoker> EventCall = new Queue<MethodInvoker>();
队列后来项目添加到您的队列
EventCall.Enqueue(ClearAllVals);
EventCall.Enqueue(saystuff);
EventCall.Enqueue(testFunc);
然后调用您的函数一次一个:
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();
或打电话给他们一个每当你想要的时间:
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.
}
}
TGhe排队不是问题;)我有一个已经和很多传输数据更新的消息。我的问题只是函数调用。队列然后使用一个ThreadPool来获得一个工作线程来处理它的内容;)我在那里有很多跨进程数据更新的东西 - 现在我正在寻找一种方法来排队(在线)方法调用。一种消息类型没有“数据”,但具有所有参数的函数调用,所以我可以基本调用目标服务上的方法。这将显着减少我需要的不同消息的数量... – TomTom 2010-05-05 17:04:05
我不必为了调用不同的方法而想出一个休眠开关语句。 – TomTom 2010-05-05 17:04:44
由于您正在寻找排队进程内方法调用,因此传递lambda似乎正是您正在寻找的内容...... – 2010-05-05 17:33:35