From ea6c0cd7c4b7952d12eb1495a43db539832d5b76 Mon Sep 17 00:00:00 2001 From: ZCube Date: Tue, 18 Apr 2017 03:34:44 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B8=94=EB=9F=AD=20=EB=B0=A9=EC=A7=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACTWebSocket.Core/Native.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ACTWebSocket.Core/Native.cs b/ACTWebSocket.Core/Native.cs index d98db5c..82a70a2 100644 --- a/ACTWebSocket.Core/Native.cs +++ b/ACTWebSocket.Core/Native.cs @@ -195,6 +195,15 @@ public static List SearchForWindow(string title) public static bool EnumProc(IntPtr hWnd, ref SearchData data) { + // 종료 과정 중 자신의 프로세스 체크시 정지되는 경우 있음. + // 만악의 근원 + uint id = 0; + GetWindowThreadProcessId(hWnd, out id); + if(GetCurrentProcessId() == id) + { + return true; + } + StringBuilder sb = new StringBuilder(1024); int ret = GetClassName(hWnd, sb, sb.Capacity); if(ret == 0) @@ -221,6 +230,12 @@ public class SearchData private delegate bool EnumWindowsProc(IntPtr hWnd, ref SearchData data); + [DllImport("user32.dll", SetLastError = true)] + static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); + + [DllImport("kernel32.dll")] + static extern uint GetCurrentProcessId(); + [DllImport("kernel32.dll", SetLastError = true)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [SuppressUnmanagedCodeSecurity]