private void UnhookSpotify() { if (_windowNameHook != null) { _windowNameHook.Stop(); _windowNameHook = null; } }
private void OnObjectCreate(IntPtr hWinEventHook, uint eventType, IntPtr hWnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { int pid; GetWindowThreadProcessId(hWnd, out pid); // return value is thread id i.e. not useful here if (Process.GetProcessById(pid).ProcessName == "spotify") { _objectCreateHook.Stop(); _objectCreateHook = null; HookSpotify(); } }