一个应用程序中的计划任务 (.Net C#)

发布于 2024-12-22 17:49:23 字数 215 浏览 4 评论 0原文

我有一个订阅数据库,我想每 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

阳光①夏 2024-12-29 17:49:23

您在这里有几个选择:

  • 使用 SQL 代理并设置作业与所需的计划(当然,这假设您使用的是 SQL Server)。
  • 编写一个带有计时器的 Windows 服务,用于查询数据库并执行不同的操作根据需要执行任务。

您提到计划任务,这可能是另一种选择,但这需要您自动进行设置新任务以及要运行的实际任务。使用我上面概述的选项,这两种方法都可以更轻松地实现。

You have a couple of choices here:

  • Use the SQL Agent and setup jobs with the required schedule (of course, this assumes you are using SQL Server).
  • Write a Windows Service with a timer that queries your database and executes the different tasks as needed.

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.

不及他 2024-12-29 17:49:23

我建议您使用 System.Threading.Timer 来实现这一点。要安排作业,请执行以下操作:

new Timer(_ => DoTheJob()).Change(your_interval_in_milliseconds, Timeout.Infinite);

然后当作业完成时,使用相同的代码安排下一次运行。这将防止同时运行同一作业的 2 个实例。
如果这不能正确回答您的问题,请告诉我。

I would recommend you to use System.Threading.Timer for that. To schedule a job, do the following:

new Timer(_ => DoTheJob()).Change(your_interval_in_milliseconds, Timeout.Infinite);

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.

暖风昔人 2024-12-29 17:49:23

您可能正在描述 Quartz.NET 可以为您做什么。检查一下,可能值得花一些时间。

You are maybe describing just what Quartz.NET can do for you. Check it out, it might be worth spending some time.

黄昏下泛黄的笔记 2024-12-29 17:49:23

所以你应该编写某种调度程序。它将从队列中获取任务并执行它们...您可以创建一个调度程序,例如每个任务都将在单独的线程中运行,这将显着提高性能!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文