开发者

C# Events at same time ignored

I am currently running into a problem with an eventlog monitor I created a while ago.

My application subscribes to the EntryWritten events of the EventLog. I noticed that if multiple events occurs at the same time (within the same second), only one of them raises the event which triggers my eventhandler.

_eventLog = new System.Diagnostics.EventLog(_logName);
_eventLog.EntryWritten += new EntryWrittenEventHandler(eventlog_EntryWritten);
_eventLog.EnableRaisingEvents = true;

Is it possible to avoid 开发者_JAVA技巧this behavior, so my eventlog_EntryWritten method will be called for all events that are logged to the eventlog?


It's worse than that - it's within a five second interval:

The system responds to WriteEntry only if the last write event occurred at least five seconds previously. This implies you will only receive one EntryWritten event notification within a five-second interval, even if more than one event log change occurs.

(from EventLog.EntryWritten)

If you need to track all events then (if they're yours), I'd suggest adding a wrapper function around WriteEntry that can catch all of the entries before they're even written to the log.


Events usually dont run in Async mode, and so if eventlog_EntryWritten does not finish before another event, you probably miss the events. Raise your own async event in fire and forget method. I am not sure, but probably this will be more effective. Or have your own class using polling mechanism to read the events.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜