private void UpdateProcesses()
{
// Note: additional try/catch blocks were added here to prevent stalls when Windows is put into
// suspend or hibernation.
try
{
if (!this.AutoHandleFavorites)
{
MainWindow frm = MainWindow.ext();
if (frm != null)
if ((frm.WindowState == FormWindowState.Minimized) || (!frm.Visible))
return;
}
}
catch { } // swallow any exceptions in attempting to check window minimize/visibility state
lock (this.updateLock)
{
// check existing processes for changes (auto-prune)
for (int i = 0; i < this._processDetails.Count;)
{
try
{
ProcessDetails pd = this._processDetails[i];
bool should_be_pruned = pd.ProcessHasExited;
if (!should_be_pruned)
{
string current_title = "";
if (!pd.NoAccess)
{
// 2 or 10 seconds until window title timeout, depending on slow-window detection mode
Tools.StartMethodMultithreadedAndWait(() => { current_title = Native.GetWindowTitle(pd.WindowHandle); }, (Utilities.AppEnvironment.SettingValue("SlowWindowDetection", false)) ? 10 : 2);
should_be_pruned = should_be_pruned || (pd.WindowTitle != current_title);
}
}
if (should_be_pruned)
{
if (pd.MadeBorderless)
HandlePrunedProcess(pd);
_processDetails.RemoveAt(i);
}
else
i++;
}
catch
{
// swallow any exceptions and move to the next item in the array
i++;
}
}
// add new process windows
try
{
windows.QueryProcessesWithWindows((pd) =>
{
if (_hiddenProcesses.IsHidden(pd.Proc.ProcessName))
return;
if (!_processDetails.Select(p => p.Proc.Id).Contains(pd.Proc.Id))
_processDetails.Add(pd);
}, _processDetails.WindowPtrSet);
}
catch { } // swallow any exceptions in attempting to add new windows
// update window
window.lblUpdateStatus.Text = "Right-click for more options. Last updated " + DateTime.Now.ToString();
}
}