C# 同时忽略事件
我目前遇到了我不久前创建的事件日志监视器的问题。
我的应用程序订阅 EventLog 的 EntryWritten 事件。 我注意到,如果多个事件同时发生(同一秒内),则只有其中一个事件会引发触发我的事件处理程序的事件。
_eventLog = new System.Diagnostics.EventLog(_logName);
_eventLog.EntryWritten += new EntryWrittenEventHandler(eventlog_EntryWritten);
_eventLog.EnableRaisingEvents = true;
是否可以避免这种行为,以便为记录到事件日志的所有事件调用我的 eventlog_EntryWritten 方法?
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 this behavior, so my eventlog_EntryWritten method will be called for all events that are logged to the eventlog?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
比这更糟糕 - 它在五秒的间隔内:
(来自 EventLog.EntryWritten )
如果您需要跟踪所有事件(如果它们是您的),我建议在 WriteEntry 周围添加一个包装函数,该函数可以在所有条目写入日志之前捕获它们。
It's worse than that - it's within a five second interval:
(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.
事件通常不会在异步模式下运行,因此如果 eventlog_EntryWritten 没有在另一个事件之前完成,您可能会错过这些事件。在“即发即忘”方法中引发您自己的异步事件。我不确定,但这可能会更有效。或者让您自己的类使用轮询机制来读取事件。
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.