From 7e042c10a8093854f7834f8fbbae0b32cec6907c Mon Sep 17 00:00:00 2001 From: Jaex Date: Tue, 5 Jan 2016 18:18:22 +0200 Subject: [PATCH] Added timeout to get window info list function for unexpected possibilities --- .../Forms/RectangleRegion.cs | 2 +- .../WindowsRectangleList.cs | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs b/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs index 0e3a03c8c..52ffa2be4 100644 --- a/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs +++ b/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs @@ -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); }); } } diff --git a/ShareX.ScreenCaptureLib/WindowsRectangleList.cs b/ShareX.ScreenCaptureLib/WindowsRectangleList.cs index 7b656f358..2cfb2acbe 100644 --- a/ShareX.ScreenCaptureLib/WindowsRectangleList.cs +++ b/ShareX.ScreenCaptureLib/WindowsRectangleList.cs @@ -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 windows; private HashSet parentHandles; - public List GetWindowsRectangleList() + public List GetWindowInfoListAsync(int timeout) + { + List windowInfoList = null; + + Thread t = new Thread(() => + { + try + { + windowInfoList = GetWindowInfoList(); + } + catch + { + } + }); + + t.Start(); + + if (!t.Join(timeout)) + { + t.Abort(); + } + + return windowInfoList; + } + + public List GetWindowInfoList() { windows = new List(); parentHandles = new HashSet();