static void TimerWatcher_Tick(object sender, EventArgs e) { var windowActive = new InfoWindow(); windowActive.Handle = GetForegroundWindow(); string path = GetProcessPath(windowActive.Handle); if (string.IsNullOrEmpty(path)) { return; } windowActive.File = new FileInfo(path); int length = GetWindowTextLength(windowActive.Handle); if (length == 0) { return; } StringBuilder builder = new StringBuilder(length); GetWindowText(windowActive.Handle, builder, length + 1); windowActive.Title = builder.ToString(); if (windowActive.ToString() != WindowActive.ToString()) { //fire: WindowActive = windowActive; if (WindowActivatedChanged != null) { WindowActivatedChanged(sender, e); } Console.WriteLine("Window: " + WindowActive.ToString()); } }