每周一次抛出方法的计时器 - C#、Asp.NET [英] Timer to throw Method Once a Week - C#, Asp.NET

查看:16
本文介绍了每周一次抛出方法的计时器 - C#、Asp.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 C# 和一般编码相当陌生.我正在寻找一个示例/开源计时器函数,它将用于每周在某个时间抛出一个基本方法(例如电子邮件通知).在做了一些研究之后,我发现使用 Timer 而不是 Windows 服务是明智的,因为它的工作量非常小.

I'm fairly new to C# and coding in general. I'm looking for an example/open source Timer Function that will be used to throw a basic method (ex. Email Notifications) once a week at a certain time. After doing some research I've found that using a Timer instead of a Windows Service would be wise as it will have a very small workload.

我在 CodePlex 和 Code Project 上找到了几个计时器 API,但由于我对 C# 的了解很少,因此在完成示例时遇到了麻烦.

I've found a couple timer API's on CodePlex and Code Project but am having trouble working my way through the Examples due to my minimal knowledge of C#.

有谁知道我可以使用的一个简单的计时器,它对初学者很友好,而且还可以走一遍?或者是否有使用 System.Timers 更简单的方法?

Does anyone know of a Simple timer that I could use that is Beginner friendly and that also has a walk through? Or is there a simpler way of doing this using System.Timers?

我的最终目标是有一个计时器,可以在每周一上午 8:00 触发一个方法.

My end goal is to have a timer that will fire a Method at 8:00AM every Monday.

我相信我应该在我最初的帖子中更详细.我选择不使用 Windows 任务计划程序的原因是因为我调用的方法比仅调用 Windows 任务更复杂.

I believe I should have been more detailed in my initial Post. The reason I chose not to use the Windows Task Scheduler is because the Method I am invoking is more complex than just invoking Windows Task.

当计时器达到预定时间时,它将触发一个方法,该方法在特定时间范围内向数据库查询需要服务的项目.然后,这将遍历项目,将它们添加到电子邮件中,该电子邮件将发送给该​​仓库的管理员.

When the timer hits the scheduled time it will fire a Method which queries the DB for Items requiring service within a certain time-frame. This will then loop through the items adding them to an email which will be sent to that Warehouse's Admin.

如果我没记错的话,那不能通过 Windows 任务计划程序完成?

If I'm not mistaken, that cannot be done through Windows Task Scheduler?

推荐答案

为此使用计时器毫无意义.你的目标是在特定时间触发一个函数.如果您的服务器重新启动怎么办?您的计时器是否会计算重新启动时间和星期一上午 8:00 之间的确切时间?

Using a timer for this makes no sense. Your goal is to have a function fire at a specific time. What if your server reboots? Is your timer going to calculate the exact time between the reboot time and Monday at 8:00 am?

IMO,使用控制台应用程序和 Windows 任务计划程序.

IMO, use a console application and the Windows Task Scheduler.

对编辑的回应:当然,您可以使用 Windows 任务计划程序.调度程序的唯一功能是执行任务.它执行的任务的复杂性没有规则.另外,查询数据库和发送电子邮件并不是一项过于复杂的任务.:)

Response to edit: Of course you can use Windows Task Scheduler for this. The only function of the scheduler is to execute a task. There are no rules as to the complexity of the task it executes. Plus, querying a DB and sending an email isn't exactly an overly complex task. :)

这篇关于每周一次抛出方法的计时器 - C#、Asp.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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