时间流逝或整数达到指定限制 - 怎么办? (C#)
我正在运行一个 C# 程序(控制台应用程序,很快将转换为 Windows 服务),我需要能够向管理员发送有关服务中错误的电子邮件,但我需要它不要针对每个错误向我们发送电子邮件,如果最近几分钟的错误数量超过 4-5 个,因此它只会发送一封电子邮件,说明存在多个错误。
我知道我会以某种形式使用计时器,但是任何人都可以提供更具体的建议吗?我将非常感激
I'm running a C# program (console application, soon to be converted to a Windows Service) where I need to be able to email administrators about errors in the service, but I need it to not send our an email for every error if the number of errors in the last few minutes exceeds 4-5, so it'll only send one email saying there are multiple errors.
I understand I'd use a timer in someform, but can anyone offer any more specific advice? I'd be very grateful
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
修改自MSDN。请注意有关
Timer
对象aTimer
声明和清理的注释。Modified from MSDN. Note comments about declaration and cleanup of
Timer
objectaTimer
.如果您使用数据库跟踪发送的每封电子邮件,则可以随时轮询数据库,以查看在给定时间段内针对给定错误您看到了多少封电子邮件等。在我参与过的几个项目中,电子邮件是一个很重要的问题。要求,记录发送的电子邮件始终是一个姐妹要求,从而为您的问题创建解决方案。
If you track each email you send using a database, you can always poll the database to see how many emails you have seen for a given error over a given period of time etc. In the few projects I've worked on where emailing was a requirement, logging of sent emails has always been a sister requirement, thus creating a solution to your problem.
使用将错误保存在列表中,然后使用 System.Threading.Timer< /a>.
传递一个封装 SendEmail 方法的委托。
Use save the errors in a list then use System.Threading.Timer.
Pass a delegate that wraps up a SendEmail method.