public SystemForegroundTitleListener() { _HandleSystemForegroundEvent = HandleSystemForegroundEvent; _HandleObjectNamechangeEvent = HandleObjectNamechangeEvent; Refs.Set(ref hFocusedApplicationEvent, SetWinEventHook(Api.EVENT_SYSTEM_FOREGROUND, _HandleSystemForegroundEvent)); }
private SingleFileRowWriter EnsureOpenedLogFile(string fileName) { if (writer == null || writer.OpenedFile != fileName) { Refs.Set(ref writer, OpenLogFile(fileName)); } return(writer); }
protected virtual void Dispose(bool disposing) { Refs.Dispose(hFocusedApplicationEvent); Refs.Dispose(hWindowTitleChangeEvent); // TODO: we must find a way to keep those delegate references alive. Ts there really no way in .NET to really keep these delegates from being collected? // Putting GC.KeepAlive will at least prevent the compiler from optimizing out the field references, but it is still possible that the delegate is collected earlier // during a gc run GC.KeepAlive(_HandleSystemForegroundEvent); GC.KeepAlive(_HandleObjectNamechangeEvent); }
private void HandleSystemForegroundEvent(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { if (hwnd == previousHwnd) { return; } var threadId = Api.GetWindowThreadProcessId(hwnd, out var processId); Refs.Set(ref hWindowTitleChangeEvent, SetWinEventHook(Api.EVENT_OBJECT_NAMECHANGE, processId, threadId, _HandleObjectNamechangeEvent)); previousHwnd = hwnd; FireForegroundTitleProbablyChanged(); }
protected virtual void Dispose(bool disposing) { Refs.Dispose(CsvWriter); }
private void FireForegroundTitleProbablyChanged() { Refs.Fire(ForegroundTitleProbablyChanged); }
private void DisposeNonDesigner(bool disposing) { Refs.Dispose(systemFocusTitleListener); }
private void ActivityMonitorMainForm_FormClosed(object sender, FormClosedEventArgs e) { Refs.Dispose(rowWriter); }