在 .Net 中创建提醒服务的最佳方式是什么?

发布于 2024-08-23 04:54:35 字数 231 浏览 7 评论 0原文

我希望构建一个 Web 应用程序,允许用户管理简单的任务或待办事项。作为其中的一部分,我想每天向用户发送有关其任务的电子邮件提醒。不过,我希望系统中的每个用户指定他们在一天中的什么时间收到提醒。例如,一个用户可以指定在上午 8 点接收电子邮件,而另一用户可能选择在晚上 7 点接收电子邮件。使用.Net,架构和构建此“提醒”服务的最佳方法是什么?另外,作为未来的阶段,我想将提醒扩展到短信和/或其他形式的通知。

任何指导将不胜感激。

I am looking to build a web application that will allow users to manage simple tasks or todos. As part of this, I'd like to send users email reminders daily of their tasks. I'd like each user in the system to specify what time of day they get their reminder, though. For example, one user can specify to get their emails at 8AM while another user might choose to get their emails at 7PM. Using .Net, what is the best way to architect and build this "reminder" service? Also, as a future phase to this, I'd like to expand the reminders to SMS text and/or other forms of notification.

Any guidance would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

夜未央樱花落 2024-08-30 04:54:35

我将创建一个始终运行的服务,并每分钟检查一次以执行任务。然后您可以执行您需要的任何操作。您可以创建一个网站供用户使用,该网站会访问该服务也读取的数据库。如果您想要更花哨的服务和 WCF 接口,请让网站转到该服务并将您需要的提醒存储在数据库中。

I would create a service that runs all the time and checks once a minute for task to preform. You could then preform what ever actions you need. you can create a website for users to use that goes to a database that the service also reads off of. If you want to get a little more fancy and a WCF interface to your service have the website go to the service and store your needed reminders in the database.

停顿的约定 2024-08-30 04:54:35

您的问题有点宽泛,但是有两种在 Windows 上处理重复发生的任务的通用方法:

  • 编写一个服务,并将其设计为定期检查任务。您可能让它在每个量程中轮询数据库,并执行当时到期的任何提醒(标记已完成的提醒)。
  • 将程序作为 Windows 计划任务运行(相当于 Microsoft 的 cron)。每小时运行一次,并按上述方法检查数据库。

我假设您知道如何从 .NET 发送电子邮件 - 这非常简单,并且大多数运营商都有邮件到 SMS 网关。

Your question is a little broad, but there are two general approaches to handling reoccurring tasks on Windows:

  • Write a service, and design it to check for tasks periodically. You might have it poll a database every quantum, and execute any reminders due at that time (marking off those it's completed).
  • Run a program as a Windows scheduled task (the Microsoft equivalent of cron). Run it every hour, and check a database as above.

I'm assuming you know how to send email from .NET - that's pretty straightforward, and most carriers have mail-to-SMS gateways.

瀟灑尐姊 2024-08-30 04:54:35

我想你可以通过两种方式做到这一点:

  • 在后台运行的Windows服务,它轮询数据库,在当前时间查找项目,如果什么也没找到就休眠,循环

    这已经足够好了,但如果突然有 1,000 个项目需要在 30 秒左右处理,则可能无法很好地扩展,因为需要很长时间才能完成。您可以通过在构建时考虑 MSMQ 来解决这个问题,它允许在不同的机器上分发,等等。

  • 类似的 Windows 服务,但可以通过某种脉冲/等待系统进行交互,每次创建新的数据库条目时都会触发该系统。然后它可以合法地睡眠,但有点“脆弱”。

我可能会采用第一种方法。

I suppose you could do it two ways:

  • Windows Service running in the background, which polls the DB, looks for items at the current time, sleeps if it finds nothing, loops

    This is fine enough, but may not scale well if suddenly there are 1,000s of items to process in 30 seconds, or so, as it will take too long to do it. You can get around this by building it with MSMQ in mind, which allows distribution over different machines, and so on.

  • Similar Windows Service, but have it interactable via some sort of pulse/wait system, which is fired each time a new DB entry gets made. Then it can legitimately sleep, but is kind of "brittle".

I'd probably go with the first approach.

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