日期:2014-05-18 浏览次数:20913 次
public class A { public static A() { System.Timers.Timer aTimer = new System.Timers.Timer(); aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent); aTimer.Interval=1000; aTimer.Enabled=true; } private static void OnTimedEvent(object source, ElapsedEventArgs e) { B.p++; // 如何定义事件来判断 p=x 时执行 C.SomeMethod() } } public static class B { public static int p; } public static class C { public static void SomeMethod() { } public static void New_x_Value() { // 随着程序进行,新x值产生,OnTimedEvent里p再次等于新x值时重新触发C.Somemethod() }
// 如何定义事件来判断 p=x 时执行 C.SomeMethod() public partial class B { public int count = 0; public delegate void doSomeThings(); public event doSomeThings doEvent; public void AddCount(int then) { count++; if (count == then) { doEvent(); } } }