为我自己的任务调度程序动态创建计时器 [英] Dynamic creating timer for my own task scheduler

查看:87
本文介绍了为我自己的任务调度程序动态创建计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建自己的任务调度程序。

I want to make my own task scheduler.

我试图动态创建计时器但失败了。

I tried to create timer dynamically but failed.

目前最大数量为我的任务调度程序足够10。

Currently maximum number of my task scheduler is enough as 10.

我提前在设计时放了10个计时器,并在每次添加任务时启用。

I put 10 timers at design time in advance and enable whenever task is added.

但是我认为这个方式不灵活。

However I think this way is not flexible.

如何在运行时动态创建计时器并处理每个计时器的事件?

How do I create timer dynamically in run-time and handle event of each timer?

推荐答案

如何使用1个计时器并设置触发任务的最小时间单位(比如15分钟),然后对于每个任务,在下次运行任务时存储。最后,在timer elapsed事件中,检查任务列表,看看
任务是否应该运行。

How about just use 1 timer and set the smallest unit of time for tasks to be triggered (say, 15 minutes), and then for your each tasks, stores the next time the task has to run. Finally, on timer elapsed event, check the list of tasks and see whether the task is due to run.

您可能希望在程序启动时使用另一个计时器来启用主计时器开始计时,例如12/30/45/00(根据您选择的"最小时间单位"调整)分钟,使其与时钟同步。

You may want to use another timer on program start to enable the main timer to start ticking at, say, 12/30/45/00 (adjust according to your selected "smallest unit of time") minutes to make it sync with the clock.

这篇关于为我自己的任务调度程序动态创建计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆