日期:2014-05-17 浏览次数:20672 次
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Monitor monitor = new Monitor(); monitor.OnReportState += state => { Console.WriteLine(state); }; monitor.StartMonitor(); Console.ReadKey(); } } public class Monitor { public delegate void ReportStateHandler(State staet); public event ReportStateHandler OnReportState; public void StartMonitor() { State state; for (Int32 i = 0; i < 100; i++) { if (i >= 0 && i < 33) { state = State.Low; } else if (i >= 33 && i < 66) { state = State.Medium; } else { state = State.High; } if (OnReportState != null) { OnReportState(state); } System.Threading.Thread.Sleep(30); } } } public enum State { Low, Medium, High } }