【发布时间】:2009-11-25 11:09:11
【问题描述】:
我有一个服务器应用程序需要安排方法的延迟执行。换句话说,在一定时间后使用 ThreadPool 中的线程运行方法的机制。
void ScheduleExecution (int delay, Action someMethod){
//How to implement this???
}
//At some other place
//MethodX will be executed on a thread in ThreadPool after 5 seconds
ScheduleExecution (5000, MethodX);
请提出一种有效的机制来实现上述目标。我宁愿避免频繁创建新对象,因为上述活动很可能在服务器上发生很多。调用的准确性也很重要,即 MethodX 在 5200 毫秒后执行很好,但在 6000 毫秒后执行是个问题。
提前谢谢...
【问题讨论】:
标签: c# .net multithreading scheduling