Skip to content

Commit

Permalink
Merge pull request #161 from mikel785/develop
Browse files Browse the repository at this point in the history
Drastically improved performance of AppChooser.Refresh()
  • Loading branch information
batzen committed Feb 15, 2020
2 parents f48ec23 + 0abf393 commit 22ad4cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Snoop/AppChooser.xaml.cs
Expand Up @@ -62,13 +62,18 @@ public void Refresh()
{
Mouse.OverrideCursor = Cursors.Wait;
foreach (var windowHandle in NativeMethods.ToplevelWindows)
var processes = Process.GetProcesses().Except(new[] { Process.GetCurrentProcess() });
foreach (var process in processes)
{
var windowInfo = new WindowInfo(windowHandle);
if (windowInfo.IsValidProcess
&& !this.IsAlreadInList(windowInfo.OwningProcessInfo.Process))
var windows = NativeMethods.GetRootWindowsOfProcess(process.Id);
var windowInfoCollection = windows.Select(h => new WindowInfo(h, process));
foreach (var windowInfo in windowInfoCollection)
{
this.windowInfos.Add(windowInfo);
if (windowInfo.IsValidProcess && !this.IsAlreadInList(process))
{
this.windowInfos.Add(windowInfo);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Snoop/WindowInfo.cs
Expand Up @@ -23,6 +23,12 @@ public WindowInfo(IntPtr hwnd)
this.HWnd = hwnd;
}

public WindowInfo(IntPtr hwnd, Process owningProcess)
: this(hwnd)
{
this.owningProcessInfo = new ProcessInfo(owningProcess);
}

public static void ClearCachedWindowHandleInfo()
{
windowHandleToValidityMap.Clear();
Expand Down

0 comments on commit 22ad4cf

Please sign in to comment.