public static void add_timer(update_control_func updater, terminate_update_func terminator, int refresh_ms = 100) { updater(false); Timer t = new Timer() { Interval = refresh_ms }; t.Tick += (sender, args) => { bool has_terminated = terminator(); if (has_terminated) { t.Enabled = false; t.Dispose(); } updater(has_terminated); }; t.Enabled = true; }
// update_ms = how long to update the control visually public static void add_timer(update_control_func updater, int update_ms, int refresh_ms = 100) { DateTime end = DateTime.Now.AddMilliseconds(update_ms); add_timer( updater, () => (DateTime.Now > end), refresh_ms ); }
public static void add_timer(update_control_func updater, terminate_update_func terminator, int refresh_ms = 100) { updater(false); Timer t = new Timer(){ Interval = refresh_ms }; t.Tick += (sender, args) => { bool has_terminated = terminator(); updater(has_terminated); if (has_terminated) { t.Enabled = false; t.Dispose(); } }; t.Enabled = true; }
// update_ms = how long to set_aliases the control visually public static void add_timer(update_control_func updater, int update_ms, int refresh_ms = 100) { DateTime end = DateTime.Now.AddMilliseconds(update_ms); add_timer(updater, () => (DateTime.Now > end), refresh_ms); }