I m 运行一个C#方案(假释申请,很快将转换为Windows Service),在该方案中,我需要能够就服务中的错误向管理人员发出电子邮件,但是,如果过去几分钟的错误数超过4-5,我就不必寄给我们一个电子邮件,指出存在多种错误。
我的理解是,我是在某种方式中使用一个时间,但任何人都能够提供更为具体的建议? 我非常感谢
I m 运行一个C#方案(假释申请,很快将转换为Windows Service),在该方案中,我需要能够就服务中的错误向管理人员发出电子邮件,但是,如果过去几分钟的错误数超过4-5,我就不必寄给我们一个电子邮件,指出存在多种错误。
我的理解是,我是在某种方式中使用一个时间,但任何人都能够提供更为具体的建议? 我非常感谢
由MSDN修改。 http://www.un.org/Depts/DGACM/index_french.htm
using System;
using System.Timers;
using System.Threading;
public class Timer2
{
private static System.Timers.Timer aTimer;
private static List<string> errors = new List<string>();
private static readonly int interval = 300000; // 5 minutes at present
private static readonly int trigger = 10; // send msg if > 10 errors
// Message processing - error detection
public static void processMessage(Message message)
{
// do the work here
// then check error
if (message.HasError)
{
// add error to pending list
lock (errors)
{
string newErrorData = "got another one!";
errors.Add(newErrorData);
++trigger;
}
}
}
public static void Main()
{
// Normally, the timer is declared at the class level,
// so that it stays in scope as long as it is needed.
// If the timer is declared in a long-running method,
// KeepAlive must be used to prevent the JIT compiler
// from allowing aggressive garbage collection to occur
// before the method ends. (See end of method.)
//System.Timers.Timer aTimer;
// Create a timer with specified interval.
aTimer = new System.Timers.Timer(interval);
// Hook up the event handler for the Elapsed event.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Enabled = true;
// Kick off message handling - don t forget to clean up the timer when
// you wish to exit
while (moreMessages)
{
Message message = getNextmessage();
ProcessMessage(message);
}
// cleanup here when messages are drained
// If the timer is declared in a long-running method, use
// KeepAlive to prevent garbage collection from occurring
// before the method ends.
//GC.KeepAlive(aTimer); }
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
object errorEmail = null;
lock (errors)
{
if (errors.Count > trigger)
{
// init message to contain errors here
errorEmail = new ErrorEmail();
foreach (string err in errors)
{
// add error info to message
}
errors.Clear();
trigger = 0;
}
}
if (errorEmail != null)
{
// send message outside the lock
Send(errorEmail);
}
}
}
如果你跟踪你使用数据库发送的每封电子邮件,你就能够总是对数据库进行勘测,以了解你在一定时期内看到的某一错误。 在少数几个项目中,我曾努力在什么地方进行电子邮件,发送电子邮件的登记一直是姐妹要求,从而解决你的问题。
使用清单中的错误,然后使用。 系统:阅读。
通过一名代表,总结电子邮件方法。
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...