public static KRPC.Service.Messages.Event OnTimer(uint milliseconds, uint repeats = 1) { var evnt = new KRPC.Service.Event (); var timer = new System.Timers.Timer (milliseconds); timer.Elapsed += (s, e) => { evnt.Trigger (); repeats--; if (repeats == 0) { evnt.Remove (); timer.Enabled = false; } }; timer.Start(); return evnt.Message; }
public static KRPC.Service.Messages.Event OnTimerUsingLambda(uint milliseconds) { bool triggered = false; var timer = new System.Timers.Timer (milliseconds); timer.Elapsed += (s, e) => { triggered = true; timer.Enabled = false; }; timer.Start(); var evnt = new KRPC.Service.Event ( (KRPC.Service.Event e) => { if (triggered) e.Remove(); return triggered; }); return evnt.Message; }