/// <summary> /// Prepares the buffer and makes the call. /// </summary> /// <returns>Name of the active window of focus.</returns> private string GetActiveWindowTitle() { const int nChars = 256; var Buff = new StringBuilder(nChars); IntPtr refToWin = Foreground.GetForegroundWindow(); return(Foreground.GetWindowText(refToWin, Buff, nChars) > 0 ? Buff.ToString() : null); }
private uint GetProcessIdentifier() { var pid = new uint(); IntPtr refToWin = Foreground.GetForegroundWindow(); Foreground.GetWindowThreadProcessId(refToWin, out pid); // Thread was destroyed and causes race condition. if (pid == 0) { return(this.ProcessIdentifier); } return(pid); }