C#事件同时被忽略 [英] C# Events at same time ignored

查看:189
本文介绍了C#事件同时被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遇到一个我创建的事件日志监视器的问题。

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

我的应用程序订阅了EventLog的EntryWritten事件。
我注意到,如果同时发生多个事件(在同一秒内),只有其中一个事件引发触发我的事件处理程序的事件。

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;

可以避免这种情况,所以我的eventlog_EntryWritten方法将被调用所有记录的事件事件日志?

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

推荐答案

事件通常不会以异步模式运行,所以如果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.

这篇关于C#事件同时被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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