/// <summary> /// In release mode invoke only, in debug mode use times and monitor object. /// </summary> public static void InitTimer(FrameworkElement control, Action InitializeComponent) { if (!IsDebug) { InitializeComponent.Invoke(); return; } var ih = new InitHelper(); ih.Control = control; ih.StartDate = DateTime.Now; ih.WriteLine("INIT START"); ih.EndDate = DateTime.Now; InitializeComponent.Invoke(); ih.EndDate = DateTime.Now; ih.WriteLine("INIT CON "); lock (TimersLock) Timers.Add(ih); ih.Control.Loaded += Control_Loaded; ih.Control.Unloaded += Control_Unloaded; ih.Control.IsVisibleChanged += Control_IsVisibleChanged; //ih.Control.PropertyChanged += Control_PropertyChanged; ih._Timer.Start(); }
/// <summary> /// This function will trigger once, after 2000ms when control stops visible changing. /// </summary> private static void _Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { InitHelper ih = null; // Find InitHelper by timer. lock (TimersLock) { ih = Timers.FirstOrDefault(x => Equals(x._Timer, sender)); if (ih == null) { return; } Timers.Remove(ih); _InitEndCount++; ih.WriteLine("INIT END"); // Disconnect all links. ih.Control.IsVisibleChanged -= Control_IsVisibleChanged; //ih.Control.PropertyChanged -= Control_PropertyChanged; ih.Control = null; ih._Timer.Dispose(); } }