一个应用程序中的计划任务 (.Net C#)
我有一个订阅数据库,我想每 x 分钟为每个订阅运行一次。
但是每个订阅都有自己的开始时间和结束时间+每 x 分钟应该运行该功能。
它可以同时运行多个订阅。
也许它应该看起来像一个计划任务,从一个特定时间开始,每 x 分钟运行到一个特定时间。
我希望我能正确描述我想做的事情,我的英语不是最好的。
有谁知道我如何构建应用程序来做到这一点?
I got a database of subscriptions, I want to run a for every subscriptions from one time to another every x minute.
But every subscription has its own from and to time + what every x minutes its should run the function.
Its can be many subscriptions running the same time.
Maybe its should looks like a scheduled task that starting at one specific time and runs every x minute to one specific time.
I hope I describe what I want to do right, my English is not the best.
Do anyone has any idea how I building the application todo this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您在这里有几个选择:
您提到计划任务,这可能是另一种选择,但这需要您自动进行设置新任务以及要运行的实际任务。使用我上面概述的选项,这两种方法都可以更轻松地实现。
You have a couple of choices here:
You mentioned scheduled tasks, which might be another option, but that will require you to automate the setting up of new tasks as well as the actual tasks to run. Both of these are easier to do with the options I have outlined above.
我建议您使用 System.Threading.Timer 来实现这一点。要安排作业,请执行以下操作:
然后当作业完成时,使用相同的代码安排下一次运行。这将防止同时运行同一作业的 2 个实例。
如果这不能正确回答您的问题,请告诉我。
I would recommend you to use
System.Threading.Timer
for that. To schedule a job, do the following:then when job is done, schedule next run using the same code. That would prevent running 2 instances of the same job simultaneously.
Please let me know if that does not answer your question appropriately.
您可能正在描述 Quartz.NET 可以为您做什么。检查一下,可能值得花一些时间。
You are maybe describing just what Quartz.NET can do for you. Check it out, it might be worth spending some time.
所以你应该编写某种调度程序。它将从队列中获取任务并执行它们...您可以创建一个调度程序,例如每个任务都将在单独的线程中运行,这将显着提高性能!
So you should write some kind of scheduler. It will take tasks from the queue and execute them... You can create a scheduler in such a way that every task for example will run in a separate thread and it would significantly improve performance!