博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[.NET] - EventLog.EntryWritten Event
阅读量:5302 次
发布时间:2019-06-14

本文共 2390 字,大约阅读时间需要 7 分钟。

刚看到在MSND论坛上有人问一个EventLog.EntryWritten Event相关的问题,说是在2015触发了一个2013年的EventWritten的事件,比较好奇,然后查看了下这个类:

https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.entrywritten%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

在的Remarks里看到有这么一段话:

The system responds to only if the last write event occurred at least six seconds previously. This implies you will only receive one EntryWritten event notification within a six-second interval, even if more than one event log change occurs. If you insert a sufficiently long sleep interval (around 10 seconds) between calls to , you are less likely to miss an event. However, if write events occur more frequently, you might not recieve the event notification until the next interval. Typically, missed event notifications are not lost, but delayed.

意思大概是这个时间只会在6秒内触发一次,如何将两次调用WriteEntry的时间间隔大于6s,那就不会造成事件miss,只是会被延迟。写了一个程序来测试下:

using System;using System.Collections.Generic;using System.Diagnostics;using System.Linq;using System.Text;using System.Threading.Tasks;namespace P20150409{    class Program    {        static void Main(string[] args)        {            EventLog myNewLog = new EventLog("Application", ".", "dotNET Sample App");            myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);            myNewLog.EnableRaisingEvents = true;            while (true)            {                System.Threading.Thread.Sleep(3000);                string EventWriteTime = DateTime.Now.ToString();                Console.WriteLine("Log is written at" + EventWriteTime);                myNewLog.WriteEntry("Test message written at" + EventWriteTime + " " + System.Threading.Thread.CurrentThread.ManagedThreadId, EventLogEntryType.Information);                Console.WriteLine();            }            Console.ReadLine();        }        private static void MyOnEntryWritten(object sender, EntryWrittenEventArgs e)        {            System.Threading.Thread.Sleep(6000);            Console.WriteLine("EntryWritten event is fired at" + DateTime.Now.ToString());            Console.WriteLine("Log time is" + e.Entry.Message);            Console.WriteLine();        }    }}

 以下是输出结果:

可以看到事件确实是没有被miss,而且触发的那次call EntryWrite方法与当前call EntryWrite的时间间隔越来越大,也就是说,这是有可能在两年后触发该事件。。。):

但是在把事件里的线程睡眠代码去掉后,事件是实时触发的,所谓的6s时间间隔内的限制并没有体现出来,不知道是不是测试的方式不对,还是系统的设置问题。如各位有知道,请指导下。

转载于:https://www.cnblogs.com/fred-bao/p/4411427.html

你可能感兴趣的文章
OpenNI / NITE的Stable版更新
查看>>
03 基本数据结构 - 栈
查看>>
Hyper-V虚拟机上安装一个图形界面的Linux系统
查看>>
微信小程序之随笔
查看>>
每秒处理10万高并发订单的乐视集团支付系统架构分享
查看>>
Lua_02
查看>>
ios蓝牙详解
查看>>
安装MySQL5.7.18遇到的坑
查看>>
React Native在Android平台运行gif的解决方法转载
查看>>
Mybatis RowBounds 是逻辑分页
查看>>
hdu 3341(ac自动机+状态压缩)
查看>>
51单片机之蓝牙遥控小车_效果展示+单片机知识+完整蓝牙电车代码
查看>>
Sql Server中REPLACE函数的使用
查看>>
SqlServerl的行转列
查看>>
JavaScript跨域总结与解决办法
查看>>
Hover功能
查看>>
[LeetCode] Jump Game II
查看>>
js千分位处理
查看>>
js常用的方法
查看>>
Mac---------三指拖移
查看>>