Added timeout to get window info list function for unexpected possibilities

This commit is contained in:
Jaex 2016-01-05 18:18:22 +02:00
parent 3e2f34468c
commit 7e042c10a8
2 changed files with 29 additions and 2 deletions

View file

@ -182,7 +182,7 @@ public override void Prepare()
WindowsRectangleList wla = new WindowsRectangleList();
wla.IgnoreHandle = handle;
wla.IncludeChildWindows = AreaManager.IncludeControls;
AreaManager.Windows = wla.GetWindowsRectangleList();
AreaManager.Windows = wla.GetWindowInfoListAsync(3000);
});
}
}

View file

@ -27,6 +27,8 @@ You should have received a copy of the GNU General Public License
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
namespace ShareX.ScreenCaptureLib
{
@ -38,7 +40,32 @@ public class WindowsRectangleList
private List<SimpleWindowInfo> windows;
private HashSet<IntPtr> parentHandles;
public List<SimpleWindowInfo> GetWindowsRectangleList()
public List<SimpleWindowInfo> GetWindowInfoListAsync(int timeout)
{
List<SimpleWindowInfo> windowInfoList = null;
Thread t = new Thread(() =>
{
try
{
windowInfoList = GetWindowInfoList();
}
catch
{
}
});
t.Start();
if (!t.Join(timeout))
{
t.Abort();
}
return windowInfoList;
}
public List<SimpleWindowInfo> GetWindowInfoList()
{
windows = new List<SimpleWindowInfo>();
parentHandles = new HashSet<IntPtr>();