private bool HandleFrameworkUpdate(IntPtr framework) { try { Gui.Chat.UpdateQueue(this); Network.UpdateQueue(this); } catch (Exception ex) { Log.Error(ex, "Exception while handling Framework::Update hook."); } try { if (StatsEnabled && OnUpdateEvent != null) { // Stat Tracking for Framework Updates var invokeList = OnUpdateEvent.GetInvocationList(); var notUpdated = StatsHistory.Keys.ToList(); // Individually invoke OnUpdate handlers and time them. foreach (var d in invokeList) { statsStopwatch.Restart(); d.Method.Invoke(d.Target, new object[] { this }); statsStopwatch.Stop(); var key = $"{d.Target}::{d.Method.Name}"; if (notUpdated.Contains(key)) { notUpdated.Remove(key); } if (!StatsHistory.ContainsKey(key)) { StatsHistory.Add(key, new List <double>()); } StatsHistory[key].Add(statsStopwatch.Elapsed.TotalMilliseconds); if (StatsHistory[key].Count > 1000) { StatsHistory[key].RemoveRange(0, StatsHistory[key].Count - 1000); } } // Cleanup handlers that are no longer being called foreach (var key in notUpdated) { if (StatsHistory[key].Count > 0) { StatsHistory[key].RemoveAt(0); } else { StatsHistory.Remove(key); } } } else { OnUpdateEvent?.Invoke(this); } } catch (Exception ex) { Log.Error(ex, "Exception while dispatching Framework::Update event."); } return(this.updateHook.Original(framework)); }